blob: 04c511bf07a43fc150a3aee3b813de99e4f10a19 [file] [log] [blame]
Fred Drake3a0351c1998-04-04 07:23:21 +00001\section{Built-in Module \module{macdnr}}
Fred Drakefe7f3bc1998-07-23 17:55:31 +00002\declaremodule{builtin}{macdnr}
3
4\modulesynopsis{Interfaces to the Macintosh Domain Name Resolver.}
5
Jack Jansenf16d5fa1995-03-02 14:41:55 +00006
7This module provides an interface to the Macintosh Domain Name
Fred Drakeaf5c0fc1998-03-17 02:02:51 +00008Resolver. It is usually used in conjunction with the \module{mactcp}
Fred Drake41788db1998-04-04 06:23:02 +00009module, to map hostnames to IP addresses. It may not be available in
Guido van Rossum96628a91995-04-10 11:34:00 +000010all Mac Python versions.
Fred Drake41788db1998-04-04 06:23:02 +000011\index{Macintosh Domain Name Resolver}
12\index{Domain Name Resolver, Macintosh}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000013
Fred Drakeaf5c0fc1998-03-17 02:02:51 +000014The \module{macdnr} module defines the following functions:
Jack Jansenf16d5fa1995-03-02 14:41:55 +000015
Jack Jansenf16d5fa1995-03-02 14:41:55 +000016
17\begin{funcdesc}{Open}{\optional{filename}}
Guido van Rossum96628a91995-04-10 11:34:00 +000018Open the domain name resolver extension. If \var{filename} is given it
Jack Jansenf16d5fa1995-03-02 14:41:55 +000019should be the pathname of the extension, otherwise a default is
Guido van Rossum96628a91995-04-10 11:34:00 +000020used. Normally, this call is not needed since the other calls will
Jack Jansenf16d5fa1995-03-02 14:41:55 +000021open the extension automatically.
22\end{funcdesc}
23
24\begin{funcdesc}{Close}{}
Guido van Rossum96628a91995-04-10 11:34:00 +000025Close the resolver extension. Again, not needed for normal use.
Jack Jansenf16d5fa1995-03-02 14:41:55 +000026\end{funcdesc}
27
28\begin{funcdesc}{StrToAddr}{hostname}
Guido van Rossum96628a91995-04-10 11:34:00 +000029Look up the IP address for \var{hostname}. This call returns a dnr
Jack Jansenf16d5fa1995-03-02 14:41:55 +000030result object of the ``address'' variation.
31\end{funcdesc}
32
33\begin{funcdesc}{AddrToName}{addr}
34Do a reverse lookup on the 32-bit integer IP-address
Guido van Rossum96628a91995-04-10 11:34:00 +000035\var{addr}. Returns a dnr result object of the ``address'' variation.
Jack Jansenf16d5fa1995-03-02 14:41:55 +000036\end{funcdesc}
37
38\begin{funcdesc}{AddrToStr}{addr}
39Convert the 32-bit integer IP-address \var{addr} to a dotted-decimal
Guido van Rossum96628a91995-04-10 11:34:00 +000040string. Returns the string.
Jack Jansenf16d5fa1995-03-02 14:41:55 +000041\end{funcdesc}
42
43\begin{funcdesc}{HInfo}{hostname}
44Query the nameservers for a \code{HInfo} record for host
Guido van Rossum96628a91995-04-10 11:34:00 +000045\var{hostname}. These records contain hardware and software
Jack Jansenf16d5fa1995-03-02 14:41:55 +000046information about the machine in question (if they are available in
Guido van Rossum96628a91995-04-10 11:34:00 +000047the first place). Returns a dnr result object of the ``hinfo''
Jack Jansenf16d5fa1995-03-02 14:41:55 +000048variety.
49\end{funcdesc}
50
51\begin{funcdesc}{MXInfo}{domain}
Guido van Rossum96628a91995-04-10 11:34:00 +000052Query the nameservers for a mail exchanger for \var{domain}. This is
Fred Drake41788db1998-04-04 06:23:02 +000053the hostname of a host willing to accept SMTP\index{SMTP} mail for the
54given domain. Returns a dnr result object of the ``mx'' variety.
Jack Jansenf16d5fa1995-03-02 14:41:55 +000055\end{funcdesc}
56
57\subsection{dnr result object}
Fred Drake41788db1998-04-04 06:23:02 +000058\label{dnr-result-object}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000059
60Since the DNR calls all execute asynchronously you do not get the
Guido van Rossum96628a91995-04-10 11:34:00 +000061results back immediately. Instead, you get a dnr result object. You
Jack Jansenf16d5fa1995-03-02 14:41:55 +000062can check this object to see whether the query is complete, and access
63its attributes to obtain the information when it is.
64
65Alternatively, you can also reference the result attributes directly,
66this will result in an implicit wait for the query to complete.
67
Fred Drakeaf5c0fc1998-03-17 02:02:51 +000068The \member{rtnCode} and \member{cname} attributes are always
69available, the others depend on the type of query (address, hinfo or
70mx).
Jack Jansenf16d5fa1995-03-02 14:41:55 +000071
Jack Jansenf16d5fa1995-03-02 14:41:55 +000072
Fred Drakeaf5c0fc1998-03-17 02:02:51 +000073% Add args, as in {arg1, arg2 \optional{, arg3}}
Fred Drake41788db1998-04-04 06:23:02 +000074\begin{methoddesc}[dnr result]{wait}{}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000075Wait for the query to complete.
Fred Drake41788db1998-04-04 06:23:02 +000076\end{methoddesc}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000077
Fred Drakeaf5c0fc1998-03-17 02:02:51 +000078% Add args, as in {arg1, arg2 \optional{, arg3}}
Fred Drake41788db1998-04-04 06:23:02 +000079\begin{methoddesc}[dnr result]{isdone}{}
Fred Drakeaf5c0fc1998-03-17 02:02:51 +000080Return \code{1} if the query is complete.
Fred Drake41788db1998-04-04 06:23:02 +000081\end{methoddesc}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000082
Guido van Rossum470be141995-03-17 16:07:09 +000083
Fred Drake41788db1998-04-04 06:23:02 +000084\begin{memberdesc}[dnr result]{rtnCode}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000085The error code returned by the query.
Fred Drake41788db1998-04-04 06:23:02 +000086\end{memberdesc}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000087
Fred Drake41788db1998-04-04 06:23:02 +000088\begin{memberdesc}[dnr result]{cname}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000089The canonical name of the host that was queried.
Fred Drake41788db1998-04-04 06:23:02 +000090\end{memberdesc}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000091
Fred Drake41788db1998-04-04 06:23:02 +000092\begin{memberdesc}[dnr result]{ip0}
93\memberline[dnr result]{ip1}
94\memberline[dnr result]{ip2}
95\memberline[dnr result]{ip3}
Guido van Rossum96628a91995-04-10 11:34:00 +000096At most four integer IP addresses for this host. Unused entries are
97zero. Valid only for address queries.
Fred Drake41788db1998-04-04 06:23:02 +000098\end{memberdesc}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000099
Fred Drake41788db1998-04-04 06:23:02 +0000100\begin{memberdesc}[dnr result]{cpuType}
101\memberline[dnr result]{osType}
Fred Drakeaf5c0fc1998-03-17 02:02:51 +0000102Textual strings giving the machine type an OS name. Valid for ``hinfo''
Jack Jansenf16d5fa1995-03-02 14:41:55 +0000103queries.
Fred Drake41788db1998-04-04 06:23:02 +0000104\end{memberdesc}
Jack Jansenf16d5fa1995-03-02 14:41:55 +0000105
Fred Drake41788db1998-04-04 06:23:02 +0000106\begin{memberdesc}[dnr result]{exchange}
Fred Drakeaf5c0fc1998-03-17 02:02:51 +0000107The name of a mail-exchanger host. Valid for ``mx'' queries.
Fred Drake41788db1998-04-04 06:23:02 +0000108\end{memberdesc}
Jack Jansenf16d5fa1995-03-02 14:41:55 +0000109
Fred Drake41788db1998-04-04 06:23:02 +0000110\begin{memberdesc}[dnr result]{preference}
Guido van Rossum96628a91995-04-10 11:34:00 +0000111The preference of this mx record. Not too useful, since the Macintosh
Fred Drakeaf5c0fc1998-03-17 02:02:51 +0000112will only return a single mx record. Valid for ``mx'' queries only.
Fred Drake41788db1998-04-04 06:23:02 +0000113\end{memberdesc}
Jack Jansenf16d5fa1995-03-02 14:41:55 +0000114
115The simplest way to use the module to convert names to dotted-decimal
116strings, without worrying about idle time, etc:
Fred Drake19479911998-02-13 06:58:54 +0000117\begin{verbatim}
Jack Jansenf16d5fa1995-03-02 14:41:55 +0000118>>> def gethostname(name):
119... import macdnr
120... dnrr = macdnr.StrToAddr(name)
121... return macdnr.AddrToStr(dnrr.ip0)
Fred Drake19479911998-02-13 06:58:54 +0000122\end{verbatim}