blob: decd953a443d6616cd6f4ed93a74ac8510221663 [file] [log] [blame]
Guido van Rossum470be141995-03-17 16:07:09 +00001\section{Built-in Module \sectcode{macdnr}}
Guido van Rossume47da0a1997-07-17 16:34:52 +00002\label{module-macdnr}
Jack Jansenf16d5fa1995-03-02 14:41:55 +00003\bimodindex{macdnr}
4
5This module provides an interface to the Macintosh Domain Name
Fred Drakeaf5c0fc1998-03-17 02:02:51 +00006Resolver. It is usually used in conjunction with the \module{mactcp}
Guido van Rossum96628a91995-04-10 11:34:00 +00007module, to map hostnames to IP-addresses. It may not be available in
8all Mac Python versions.
Jack Jansenf16d5fa1995-03-02 14:41:55 +00009
Fred Drakeaf5c0fc1998-03-17 02:02:51 +000010The \module{macdnr} module defines the following functions:
Jack Jansenf16d5fa1995-03-02 14:41:55 +000011
Jack Jansenf16d5fa1995-03-02 14:41:55 +000012
13\begin{funcdesc}{Open}{\optional{filename}}
Guido van Rossum96628a91995-04-10 11:34:00 +000014Open the domain name resolver extension. If \var{filename} is given it
Jack Jansenf16d5fa1995-03-02 14:41:55 +000015should be the pathname of the extension, otherwise a default is
Guido van Rossum96628a91995-04-10 11:34:00 +000016used. Normally, this call is not needed since the other calls will
Jack Jansenf16d5fa1995-03-02 14:41:55 +000017open the extension automatically.
18\end{funcdesc}
19
20\begin{funcdesc}{Close}{}
Guido van Rossum96628a91995-04-10 11:34:00 +000021Close the resolver extension. Again, not needed for normal use.
Jack Jansenf16d5fa1995-03-02 14:41:55 +000022\end{funcdesc}
23
24\begin{funcdesc}{StrToAddr}{hostname}
Guido van Rossum96628a91995-04-10 11:34:00 +000025Look up the IP address for \var{hostname}. This call returns a dnr
Jack Jansenf16d5fa1995-03-02 14:41:55 +000026result object of the ``address'' variation.
27\end{funcdesc}
28
29\begin{funcdesc}{AddrToName}{addr}
30Do a reverse lookup on the 32-bit integer IP-address
Guido van Rossum96628a91995-04-10 11:34:00 +000031\var{addr}. Returns a dnr result object of the ``address'' variation.
Jack Jansenf16d5fa1995-03-02 14:41:55 +000032\end{funcdesc}
33
34\begin{funcdesc}{AddrToStr}{addr}
35Convert the 32-bit integer IP-address \var{addr} to a dotted-decimal
Guido van Rossum96628a91995-04-10 11:34:00 +000036string. Returns the string.
Jack Jansenf16d5fa1995-03-02 14:41:55 +000037\end{funcdesc}
38
39\begin{funcdesc}{HInfo}{hostname}
40Query the nameservers for a \code{HInfo} record for host
Guido van Rossum96628a91995-04-10 11:34:00 +000041\var{hostname}. These records contain hardware and software
Jack Jansenf16d5fa1995-03-02 14:41:55 +000042information about the machine in question (if they are available in
Guido van Rossum96628a91995-04-10 11:34:00 +000043the first place). Returns a dnr result object of the ``hinfo''
Jack Jansenf16d5fa1995-03-02 14:41:55 +000044variety.
45\end{funcdesc}
46
47\begin{funcdesc}{MXInfo}{domain}
Guido van Rossum96628a91995-04-10 11:34:00 +000048Query the nameservers for a mail exchanger for \var{domain}. This is
Jack Jansenf16d5fa1995-03-02 14:41:55 +000049the hostname of a host willing to accept SMTP mail for the given
Guido van Rossum96628a91995-04-10 11:34:00 +000050domain. Returns a dnr result object of the ``mx'' variety.
Jack Jansenf16d5fa1995-03-02 14:41:55 +000051\end{funcdesc}
52
53\subsection{dnr result object}
54
55Since the DNR calls all execute asynchronously you do not get the
Guido van Rossum96628a91995-04-10 11:34:00 +000056results back immediately. Instead, you get a dnr result object. You
Jack Jansenf16d5fa1995-03-02 14:41:55 +000057can check this object to see whether the query is complete, and access
58its attributes to obtain the information when it is.
59
60Alternatively, you can also reference the result attributes directly,
61this will result in an implicit wait for the query to complete.
62
Fred Drakeaf5c0fc1998-03-17 02:02:51 +000063The \member{rtnCode} and \member{cname} attributes are always
64available, the others depend on the type of query (address, hinfo or
65mx).
Jack Jansenf16d5fa1995-03-02 14:41:55 +000066
Fred Drakeaf5c0fc1998-03-17 02:02:51 +000067\setindexsubitem{(dnr result method)}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000068
Fred Drakeaf5c0fc1998-03-17 02:02:51 +000069% Add args, as in {arg1, arg2 \optional{, arg3}}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000070\begin{funcdesc}{wait}{}
71Wait for the query to complete.
72\end{funcdesc}
73
Fred Drakeaf5c0fc1998-03-17 02:02:51 +000074% Add args, as in {arg1, arg2 \optional{, arg3}}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000075\begin{funcdesc}{isdone}{}
Fred Drakeaf5c0fc1998-03-17 02:02:51 +000076Return \code{1} if the query is complete.
Jack Jansenf16d5fa1995-03-02 14:41:55 +000077\end{funcdesc}
78
Fred Drakeaf5c0fc1998-03-17 02:02:51 +000079\setindexsubitem{(dnr result attribute)}
Guido van Rossum470be141995-03-17 16:07:09 +000080
Jack Jansenf16d5fa1995-03-02 14:41:55 +000081\begin{datadesc}{rtnCode}
82The error code returned by the query.
83\end{datadesc}
84
85\begin{datadesc}{cname}
86The canonical name of the host that was queried.
87\end{datadesc}
88
89\begin{datadesc}{ip0}
90\dataline{ip1}
91\dataline{ip2}
92\dataline{ip3}
Guido van Rossum96628a91995-04-10 11:34:00 +000093At most four integer IP addresses for this host. Unused entries are
94zero. Valid only for address queries.
Jack Jansenf16d5fa1995-03-02 14:41:55 +000095\end{datadesc}
96
97\begin{datadesc}{cpuType}
98\dataline{osType}
Fred Drakeaf5c0fc1998-03-17 02:02:51 +000099Textual strings giving the machine type an OS name. Valid for ``hinfo''
Jack Jansenf16d5fa1995-03-02 14:41:55 +0000100queries.
101\end{datadesc}
102
103\begin{datadesc}{exchange}
Fred Drakeaf5c0fc1998-03-17 02:02:51 +0000104The name of a mail-exchanger host. Valid for ``mx'' queries.
Jack Jansenf16d5fa1995-03-02 14:41:55 +0000105\end{datadesc}
106
107\begin{datadesc}{preference}
Guido van Rossum96628a91995-04-10 11:34:00 +0000108The preference of this mx record. Not too useful, since the Macintosh
Fred Drakeaf5c0fc1998-03-17 02:02:51 +0000109will only return a single mx record. Valid for ``mx'' queries only.
Jack Jansenf16d5fa1995-03-02 14:41:55 +0000110\end{datadesc}
111
112The simplest way to use the module to convert names to dotted-decimal
113strings, without worrying about idle time, etc:
Fred Drake19479911998-02-13 06:58:54 +0000114\begin{verbatim}
Jack Jansenf16d5fa1995-03-02 14:41:55 +0000115>>> def gethostname(name):
116... import macdnr
117... dnrr = macdnr.StrToAddr(name)
118... return macdnr.AddrToStr(dnrr.ip0)
Fred Drake19479911998-02-13 06:58:54 +0000119\end{verbatim}