blob: efd80d4a274b32207ed4c7be106131fb4b81e880 [file] [log] [blame]
Fred Drakec817e271998-08-10 18:40:22 +00001\section{\module{macdnr} ---
Fred Drakef6863c11999-03-02 16:37:17 +00002 Interface to the Macintosh Domain Name Resolver}
Fred Drakefe7f3bc1998-07-23 17:55:31 +00003
Fred Drakef6863c11999-03-02 16:37:17 +00004\declaremodule{builtin}{macdnr}
5 \platform{Mac}
Fred Drakefe7f3bc1998-07-23 17:55:31 +00006\modulesynopsis{Interfaces to the Macintosh Domain Name Resolver.}
7
Jack Jansenf16d5fa1995-03-02 14:41:55 +00008
9This module provides an interface to the Macintosh Domain Name
Fred Drakef6863c11999-03-02 16:37:17 +000010Resolver. It is usually used in conjunction with the \refmodule{mactcp}
Fred Drake41788db1998-04-04 06:23:02 +000011module, to map hostnames to IP addresses. It may not be available in
Guido van Rossum96628a91995-04-10 11:34:00 +000012all Mac Python versions.
Fred Drake41788db1998-04-04 06:23:02 +000013\index{Macintosh Domain Name Resolver}
14\index{Domain Name Resolver, Macintosh}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000015
Fred Drakeaf5c0fc1998-03-17 02:02:51 +000016The \module{macdnr} module defines the following functions:
Jack Jansenf16d5fa1995-03-02 14:41:55 +000017
Jack Jansenf16d5fa1995-03-02 14:41:55 +000018
19\begin{funcdesc}{Open}{\optional{filename}}
Guido van Rossum96628a91995-04-10 11:34:00 +000020Open the domain name resolver extension. If \var{filename} is given it
Jack Jansenf16d5fa1995-03-02 14:41:55 +000021should be the pathname of the extension, otherwise a default is
Guido van Rossum96628a91995-04-10 11:34:00 +000022used. Normally, this call is not needed since the other calls will
Jack Jansenf16d5fa1995-03-02 14:41:55 +000023open the extension automatically.
24\end{funcdesc}
25
26\begin{funcdesc}{Close}{}
Guido van Rossum96628a91995-04-10 11:34:00 +000027Close the resolver extension. Again, not needed for normal use.
Jack Jansenf16d5fa1995-03-02 14:41:55 +000028\end{funcdesc}
29
30\begin{funcdesc}{StrToAddr}{hostname}
Guido van Rossum96628a91995-04-10 11:34:00 +000031Look up the IP address for \var{hostname}. This call returns a dnr
Jack Jansenf16d5fa1995-03-02 14:41:55 +000032result object of the ``address'' variation.
33\end{funcdesc}
34
35\begin{funcdesc}{AddrToName}{addr}
36Do a reverse lookup on the 32-bit integer IP-address
Guido van Rossum96628a91995-04-10 11:34:00 +000037\var{addr}. Returns a dnr result object of the ``address'' variation.
Jack Jansenf16d5fa1995-03-02 14:41:55 +000038\end{funcdesc}
39
40\begin{funcdesc}{AddrToStr}{addr}
41Convert the 32-bit integer IP-address \var{addr} to a dotted-decimal
Guido van Rossum96628a91995-04-10 11:34:00 +000042string. Returns the string.
Jack Jansenf16d5fa1995-03-02 14:41:55 +000043\end{funcdesc}
44
45\begin{funcdesc}{HInfo}{hostname}
46Query the nameservers for a \code{HInfo} record for host
Guido van Rossum96628a91995-04-10 11:34:00 +000047\var{hostname}. These records contain hardware and software
Jack Jansenf16d5fa1995-03-02 14:41:55 +000048information about the machine in question (if they are available in
Guido van Rossum96628a91995-04-10 11:34:00 +000049the first place). Returns a dnr result object of the ``hinfo''
Jack Jansenf16d5fa1995-03-02 14:41:55 +000050variety.
51\end{funcdesc}
52
53\begin{funcdesc}{MXInfo}{domain}
Guido van Rossum96628a91995-04-10 11:34:00 +000054Query the nameservers for a mail exchanger for \var{domain}. This is
Fred Drake41788db1998-04-04 06:23:02 +000055the hostname of a host willing to accept SMTP\index{SMTP} mail for the
56given domain. Returns a dnr result object of the ``mx'' variety.
Jack Jansenf16d5fa1995-03-02 14:41:55 +000057\end{funcdesc}
58
Fred Drakef6863c11999-03-02 16:37:17 +000059
60\subsection{DNR Result Objects \label{dnr-result-object}}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000061
62Since the DNR calls all execute asynchronously you do not get the
Guido van Rossum96628a91995-04-10 11:34:00 +000063results back immediately. Instead, you get a dnr result object. You
Jack Jansenf16d5fa1995-03-02 14:41:55 +000064can check this object to see whether the query is complete, and access
65its attributes to obtain the information when it is.
66
67Alternatively, you can also reference the result attributes directly,
68this will result in an implicit wait for the query to complete.
69
Fred Drakeaf5c0fc1998-03-17 02:02:51 +000070The \member{rtnCode} and \member{cname} attributes are always
71available, the others depend on the type of query (address, hinfo or
72mx).
Jack Jansenf16d5fa1995-03-02 14:41:55 +000073
Jack Jansenf16d5fa1995-03-02 14:41:55 +000074
Fred Drakeaf5c0fc1998-03-17 02:02:51 +000075% Add args, as in {arg1, arg2 \optional{, arg3}}
Fred Drake41788db1998-04-04 06:23:02 +000076\begin{methoddesc}[dnr result]{wait}{}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000077Wait for the query to complete.
Fred Drake41788db1998-04-04 06:23:02 +000078\end{methoddesc}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000079
Fred Drakeaf5c0fc1998-03-17 02:02:51 +000080% Add args, as in {arg1, arg2 \optional{, arg3}}
Fred Drake41788db1998-04-04 06:23:02 +000081\begin{methoddesc}[dnr result]{isdone}{}
Fred Drakeaf5c0fc1998-03-17 02:02:51 +000082Return \code{1} if the query is complete.
Fred Drake41788db1998-04-04 06:23:02 +000083\end{methoddesc}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000084
Guido van Rossum470be141995-03-17 16:07:09 +000085
Fred Drake41788db1998-04-04 06:23:02 +000086\begin{memberdesc}[dnr result]{rtnCode}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000087The error code returned by the query.
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]{cname}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000091The canonical name of the host that was queried.
Fred Drake41788db1998-04-04 06:23:02 +000092\end{memberdesc}
Jack Jansenf16d5fa1995-03-02 14:41:55 +000093
Fred Drake41788db1998-04-04 06:23:02 +000094\begin{memberdesc}[dnr result]{ip0}
Fred Drakeaf2590a1998-11-25 20:15:52 +000095\memberline{ip1}
96\memberline{ip2}
97\memberline{ip3}
Guido van Rossum96628a91995-04-10 11:34:00 +000098At most four integer IP addresses for this host. Unused entries are
99zero. Valid only for address queries.
Fred Drake41788db1998-04-04 06:23:02 +0000100\end{memberdesc}
Jack Jansenf16d5fa1995-03-02 14:41:55 +0000101
Fred Drake41788db1998-04-04 06:23:02 +0000102\begin{memberdesc}[dnr result]{cpuType}
Fred Drakeaf2590a1998-11-25 20:15:52 +0000103\memberline{osType}
Fred Drakeaf5c0fc1998-03-17 02:02:51 +0000104Textual strings giving the machine type an OS name. Valid for ``hinfo''
Jack Jansenf16d5fa1995-03-02 14:41:55 +0000105queries.
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]{exchange}
Fred Drakeaf5c0fc1998-03-17 02:02:51 +0000109The name of a mail-exchanger host. Valid for ``mx'' queries.
Fred Drake41788db1998-04-04 06:23:02 +0000110\end{memberdesc}
Jack Jansenf16d5fa1995-03-02 14:41:55 +0000111
Fred Drake41788db1998-04-04 06:23:02 +0000112\begin{memberdesc}[dnr result]{preference}
Guido van Rossum96628a91995-04-10 11:34:00 +0000113The preference of this mx record. Not too useful, since the Macintosh
Fred Drakeaf5c0fc1998-03-17 02:02:51 +0000114will only return a single mx record. Valid for ``mx'' queries only.
Fred Drake41788db1998-04-04 06:23:02 +0000115\end{memberdesc}
Jack Jansenf16d5fa1995-03-02 14:41:55 +0000116
117The simplest way to use the module to convert names to dotted-decimal
118strings, without worrying about idle time, etc:
Fred Drakef6863c11999-03-02 16:37:17 +0000119
Fred Drake19479911998-02-13 06:58:54 +0000120\begin{verbatim}
Jack Jansenf16d5fa1995-03-02 14:41:55 +0000121>>> def gethostname(name):
122... import macdnr
123... dnrr = macdnr.StrToAddr(name)
124... return macdnr.AddrToStr(dnrr.ip0)
Fred Drake19479911998-02-13 06:58:54 +0000125\end{verbatim}