blob: 2aa07f5337f72a954e068ad670288284b42672a8 [file] [log] [blame]
Fred Drake3a0351c1998-04-04 07:23:21 +00001\section{Built-in Module \module{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}
Fred Drake41788db1998-04-04 06:23:02 +00007module, to map hostnames to IP addresses. It may not be available in
Guido van Rossum96628a91995-04-10 11:34:00 +00008all Mac Python versions.
Fred Drake41788db1998-04-04 06:23:02 +00009\index{Macintosh Domain Name Resolver}
10\index{Domain Name Resolver, Macintosh}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000011
Fred Drakeaf5c0fc1998-03-17 02:02:51 +000012The \module{macdnr} module defines the following functions:
Jack Jansenf16d5fa1995-03-02 14:41:55 +000013
Jack Jansenf16d5fa1995-03-02 14:41:55 +000014
15\begin{funcdesc}{Open}{\optional{filename}}
Guido van Rossum96628a91995-04-10 11:34:00 +000016Open the domain name resolver extension. If \var{filename} is given it
Jack Jansenf16d5fa1995-03-02 14:41:55 +000017should be the pathname of the extension, otherwise a default is
Guido van Rossum96628a91995-04-10 11:34:00 +000018used. Normally, this call is not needed since the other calls will
Jack Jansenf16d5fa1995-03-02 14:41:55 +000019open the extension automatically.
20\end{funcdesc}
21
22\begin{funcdesc}{Close}{}
Guido van Rossum96628a91995-04-10 11:34:00 +000023Close the resolver extension. Again, not needed for normal use.
Jack Jansenf16d5fa1995-03-02 14:41:55 +000024\end{funcdesc}
25
26\begin{funcdesc}{StrToAddr}{hostname}
Guido van Rossum96628a91995-04-10 11:34:00 +000027Look up the IP address for \var{hostname}. This call returns a dnr
Jack Jansenf16d5fa1995-03-02 14:41:55 +000028result object of the ``address'' variation.
29\end{funcdesc}
30
31\begin{funcdesc}{AddrToName}{addr}
32Do a reverse lookup on the 32-bit integer IP-address
Guido van Rossum96628a91995-04-10 11:34:00 +000033\var{addr}. Returns a dnr result object of the ``address'' variation.
Jack Jansenf16d5fa1995-03-02 14:41:55 +000034\end{funcdesc}
35
36\begin{funcdesc}{AddrToStr}{addr}
37Convert the 32-bit integer IP-address \var{addr} to a dotted-decimal
Guido van Rossum96628a91995-04-10 11:34:00 +000038string. Returns the string.
Jack Jansenf16d5fa1995-03-02 14:41:55 +000039\end{funcdesc}
40
41\begin{funcdesc}{HInfo}{hostname}
42Query the nameservers for a \code{HInfo} record for host
Guido van Rossum96628a91995-04-10 11:34:00 +000043\var{hostname}. These records contain hardware and software
Jack Jansenf16d5fa1995-03-02 14:41:55 +000044information about the machine in question (if they are available in
Guido van Rossum96628a91995-04-10 11:34:00 +000045the first place). Returns a dnr result object of the ``hinfo''
Jack Jansenf16d5fa1995-03-02 14:41:55 +000046variety.
47\end{funcdesc}
48
49\begin{funcdesc}{MXInfo}{domain}
Guido van Rossum96628a91995-04-10 11:34:00 +000050Query the nameservers for a mail exchanger for \var{domain}. This is
Fred Drake41788db1998-04-04 06:23:02 +000051the hostname of a host willing to accept SMTP\index{SMTP} mail for the
52given domain. Returns a dnr result object of the ``mx'' variety.
Jack Jansenf16d5fa1995-03-02 14:41:55 +000053\end{funcdesc}
54
55\subsection{dnr result object}
Fred Drake41788db1998-04-04 06:23:02 +000056\label{dnr-result-object}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000057
58Since the DNR calls all execute asynchronously you do not get the
Guido van Rossum96628a91995-04-10 11:34:00 +000059results back immediately. Instead, you get a dnr result object. You
Jack Jansenf16d5fa1995-03-02 14:41:55 +000060can check this object to see whether the query is complete, and access
61its attributes to obtain the information when it is.
62
63Alternatively, you can also reference the result attributes directly,
64this will result in an implicit wait for the query to complete.
65
Fred Drakeaf5c0fc1998-03-17 02:02:51 +000066The \member{rtnCode} and \member{cname} attributes are always
67available, the others depend on the type of query (address, hinfo or
68mx).
Jack Jansenf16d5fa1995-03-02 14:41:55 +000069
Jack Jansenf16d5fa1995-03-02 14:41:55 +000070
Fred Drakeaf5c0fc1998-03-17 02:02:51 +000071% Add args, as in {arg1, arg2 \optional{, arg3}}
Fred Drake41788db1998-04-04 06:23:02 +000072\begin{methoddesc}[dnr result]{wait}{}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000073Wait for the query to complete.
Fred Drake41788db1998-04-04 06:23:02 +000074\end{methoddesc}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000075
Fred Drakeaf5c0fc1998-03-17 02:02:51 +000076% Add args, as in {arg1, arg2 \optional{, arg3}}
Fred Drake41788db1998-04-04 06:23:02 +000077\begin{methoddesc}[dnr result]{isdone}{}
Fred Drakeaf5c0fc1998-03-17 02:02:51 +000078Return \code{1} if the query is complete.
Fred Drake41788db1998-04-04 06:23:02 +000079\end{methoddesc}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000080
Guido van Rossum470be141995-03-17 16:07:09 +000081
Fred Drake41788db1998-04-04 06:23:02 +000082\begin{memberdesc}[dnr result]{rtnCode}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000083The error code returned by the query.
Fred Drake41788db1998-04-04 06:23:02 +000084\end{memberdesc}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000085
Fred Drake41788db1998-04-04 06:23:02 +000086\begin{memberdesc}[dnr result]{cname}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000087The canonical name of the host that was queried.
Fred Drake41788db1998-04-04 06:23:02 +000088\end{memberdesc}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000089
Fred Drake41788db1998-04-04 06:23:02 +000090\begin{memberdesc}[dnr result]{ip0}
91\memberline[dnr result]{ip1}
92\memberline[dnr result]{ip2}
93\memberline[dnr result]{ip3}
Guido van Rossum96628a91995-04-10 11:34:00 +000094At most four integer IP addresses for this host. Unused entries are
95zero. Valid only for address queries.
Fred Drake41788db1998-04-04 06:23:02 +000096\end{memberdesc}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000097
Fred Drake41788db1998-04-04 06:23:02 +000098\begin{memberdesc}[dnr result]{cpuType}
99\memberline[dnr result]{osType}
Fred Drakeaf5c0fc1998-03-17 02:02:51 +0000100Textual strings giving the machine type an OS name. Valid for ``hinfo''
Jack Jansenf16d5fa1995-03-02 14:41:55 +0000101queries.
Fred Drake41788db1998-04-04 06:23:02 +0000102\end{memberdesc}
Jack Jansenf16d5fa1995-03-02 14:41:55 +0000103
Fred Drake41788db1998-04-04 06:23:02 +0000104\begin{memberdesc}[dnr result]{exchange}
Fred Drakeaf5c0fc1998-03-17 02:02:51 +0000105The name of a mail-exchanger host. Valid for ``mx'' queries.
Fred Drake41788db1998-04-04 06:23:02 +0000106\end{memberdesc}
Jack Jansenf16d5fa1995-03-02 14:41:55 +0000107
Fred Drake41788db1998-04-04 06:23:02 +0000108\begin{memberdesc}[dnr result]{preference}
Guido van Rossum96628a91995-04-10 11:34:00 +0000109The preference of this mx record. Not too useful, since the Macintosh
Fred Drakeaf5c0fc1998-03-17 02:02:51 +0000110will only return a single mx record. Valid for ``mx'' queries only.
Fred Drake41788db1998-04-04 06:23:02 +0000111\end{memberdesc}
Jack Jansenf16d5fa1995-03-02 14:41:55 +0000112
113The simplest way to use the module to convert names to dotted-decimal
114strings, without worrying about idle time, etc:
Fred Drake19479911998-02-13 06:58:54 +0000115\begin{verbatim}
Jack Jansenf16d5fa1995-03-02 14:41:55 +0000116>>> def gethostname(name):
117... import macdnr
118... dnrr = macdnr.StrToAddr(name)
119... return macdnr.AddrToStr(dnrr.ip0)
Fred Drake19479911998-02-13 06:58:54 +0000120\end{verbatim}