cpython/Doc/libmacdnr.tex

121 lines
3.9 KiB
TeX
Raw Normal View History

\section{Built-in Module \sectcode{macdnr}}
\label{module-macdnr}
1995-03-02 10:41:55 -04:00
\bimodindex{macdnr}
This module provides an interface to the Macintosh Domain Name
1998-03-16 22:02:51 -04:00
Resolver. It is usually used in conjunction with the \module{mactcp}
1998-04-04 02:23:02 -04:00
module, to map hostnames to IP addresses. It may not be available in
1995-04-10 08:34:00 -03:00
all Mac Python versions.
1998-04-04 02:23:02 -04:00
\index{Macintosh Domain Name Resolver}
\index{Domain Name Resolver, Macintosh}
1995-03-02 10:41:55 -04:00
1998-03-16 22:02:51 -04:00
The \module{macdnr} module defines the following functions:
1995-03-02 10:41:55 -04:00
\begin{funcdesc}{Open}{\optional{filename}}
1995-04-10 08:34:00 -03:00
Open the domain name resolver extension. If \var{filename} is given it
1995-03-02 10:41:55 -04:00
should be the pathname of the extension, otherwise a default is
1995-04-10 08:34:00 -03:00
used. Normally, this call is not needed since the other calls will
1995-03-02 10:41:55 -04:00
open the extension automatically.
\end{funcdesc}
\begin{funcdesc}{Close}{}
1995-04-10 08:34:00 -03:00
Close the resolver extension. Again, not needed for normal use.
1995-03-02 10:41:55 -04:00
\end{funcdesc}
\begin{funcdesc}{StrToAddr}{hostname}
1995-04-10 08:34:00 -03:00
Look up the IP address for \var{hostname}. This call returns a dnr
1995-03-02 10:41:55 -04:00
result object of the ``address'' variation.
\end{funcdesc}
\begin{funcdesc}{AddrToName}{addr}
Do a reverse lookup on the 32-bit integer IP-address
1995-04-10 08:34:00 -03:00
\var{addr}. Returns a dnr result object of the ``address'' variation.
1995-03-02 10:41:55 -04:00
\end{funcdesc}
\begin{funcdesc}{AddrToStr}{addr}
Convert the 32-bit integer IP-address \var{addr} to a dotted-decimal
1995-04-10 08:34:00 -03:00
string. Returns the string.
1995-03-02 10:41:55 -04:00
\end{funcdesc}
\begin{funcdesc}{HInfo}{hostname}
Query the nameservers for a \code{HInfo} record for host
1995-04-10 08:34:00 -03:00
\var{hostname}. These records contain hardware and software
1995-03-02 10:41:55 -04:00
information about the machine in question (if they are available in
1995-04-10 08:34:00 -03:00
the first place). Returns a dnr result object of the ``hinfo''
1995-03-02 10:41:55 -04:00
variety.
\end{funcdesc}
\begin{funcdesc}{MXInfo}{domain}
1995-04-10 08:34:00 -03:00
Query the nameservers for a mail exchanger for \var{domain}. This is
1998-04-04 02:23:02 -04:00
the hostname of a host willing to accept SMTP\index{SMTP} mail for the
given domain. Returns a dnr result object of the ``mx'' variety.
1995-03-02 10:41:55 -04:00
\end{funcdesc}
\subsection{dnr result object}
1998-04-04 02:23:02 -04:00
\label{dnr-result-object}
1995-03-02 10:41:55 -04:00
Since the DNR calls all execute asynchronously you do not get the
1995-04-10 08:34:00 -03:00
results back immediately. Instead, you get a dnr result object. You
1995-03-02 10:41:55 -04:00
can check this object to see whether the query is complete, and access
its attributes to obtain the information when it is.
Alternatively, you can also reference the result attributes directly,
this will result in an implicit wait for the query to complete.
1998-03-16 22:02:51 -04:00
The \member{rtnCode} and \member{cname} attributes are always
available, the others depend on the type of query (address, hinfo or
mx).
1995-03-02 10:41:55 -04:00
1998-03-16 22:02:51 -04:00
% Add args, as in {arg1, arg2 \optional{, arg3}}
1998-04-04 02:23:02 -04:00
\begin{methoddesc}[dnr result]{wait}{}
1995-03-02 10:41:55 -04:00
Wait for the query to complete.
1998-04-04 02:23:02 -04:00
\end{methoddesc}
1995-03-02 10:41:55 -04:00
1998-03-16 22:02:51 -04:00
% Add args, as in {arg1, arg2 \optional{, arg3}}
1998-04-04 02:23:02 -04:00
\begin{methoddesc}[dnr result]{isdone}{}
1998-03-16 22:02:51 -04:00
Return \code{1} if the query is complete.
1998-04-04 02:23:02 -04:00
\end{methoddesc}
1995-03-02 10:41:55 -04:00
1998-04-04 02:23:02 -04:00
\begin{memberdesc}[dnr result]{rtnCode}
1995-03-02 10:41:55 -04:00
The error code returned by the query.
1998-04-04 02:23:02 -04:00
\end{memberdesc}
1995-03-02 10:41:55 -04:00
1998-04-04 02:23:02 -04:00
\begin{memberdesc}[dnr result]{cname}
1995-03-02 10:41:55 -04:00
The canonical name of the host that was queried.
1998-04-04 02:23:02 -04:00
\end{memberdesc}
1995-03-02 10:41:55 -04:00
1998-04-04 02:23:02 -04:00
\begin{memberdesc}[dnr result]{ip0}
\memberline[dnr result]{ip1}
\memberline[dnr result]{ip2}
\memberline[dnr result]{ip3}
1995-04-10 08:34:00 -03:00
At most four integer IP addresses for this host. Unused entries are
zero. Valid only for address queries.
1998-04-04 02:23:02 -04:00
\end{memberdesc}
1995-03-02 10:41:55 -04:00
1998-04-04 02:23:02 -04:00
\begin{memberdesc}[dnr result]{cpuType}
\memberline[dnr result]{osType}
1998-03-16 22:02:51 -04:00
Textual strings giving the machine type an OS name. Valid for ``hinfo''
1995-03-02 10:41:55 -04:00
queries.
1998-04-04 02:23:02 -04:00
\end{memberdesc}
1995-03-02 10:41:55 -04:00
1998-04-04 02:23:02 -04:00
\begin{memberdesc}[dnr result]{exchange}
1998-03-16 22:02:51 -04:00
The name of a mail-exchanger host. Valid for ``mx'' queries.
1998-04-04 02:23:02 -04:00
\end{memberdesc}
1995-03-02 10:41:55 -04:00
1998-04-04 02:23:02 -04:00
\begin{memberdesc}[dnr result]{preference}
1995-04-10 08:34:00 -03:00
The preference of this mx record. Not too useful, since the Macintosh
1998-03-16 22:02:51 -04:00
will only return a single mx record. Valid for ``mx'' queries only.
1998-04-04 02:23:02 -04:00
\end{memberdesc}
1995-03-02 10:41:55 -04:00
The simplest way to use the module to convert names to dotted-decimal
strings, without worrying about idle time, etc:
\begin{verbatim}
1995-03-02 10:41:55 -04:00
>>> def gethostname(name):
... import macdnr
... dnrr = macdnr.StrToAddr(name)
... return macdnr.AddrToStr(dnrr.ip0)
\end{verbatim}