cpython/Doc/mac/libmacdnr.tex

120 lines
3.7 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}
1995-04-10 08:34:00 -03:00
module, to map hostnames to IP-addresses. It may not be available in
all Mac Python versions.
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
1995-03-02 10:41:55 -04:00
the hostname of a host willing to accept SMTP mail for the given
1995-04-10 08:34:00 -03:00
domain. Returns a dnr result object of the ``mx'' variety.
1995-03-02 10:41:55 -04:00
\end{funcdesc}
\subsection{dnr result object}
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
\setindexsubitem{(dnr result method)}
1995-03-02 10:41:55 -04:00
1998-03-16 22:02:51 -04:00
% Add args, as in {arg1, arg2 \optional{, arg3}}
1995-03-02 10:41:55 -04:00
\begin{funcdesc}{wait}{}
Wait for the query to complete.
\end{funcdesc}
1998-03-16 22:02:51 -04:00
% Add args, as in {arg1, arg2 \optional{, arg3}}
1995-03-02 10:41:55 -04:00
\begin{funcdesc}{isdone}{}
1998-03-16 22:02:51 -04:00
Return \code{1} if the query is complete.
1995-03-02 10:41:55 -04:00
\end{funcdesc}
1998-03-16 22:02:51 -04:00
\setindexsubitem{(dnr result attribute)}
1995-03-02 10:41:55 -04:00
\begin{datadesc}{rtnCode}
The error code returned by the query.
\end{datadesc}
\begin{datadesc}{cname}
The canonical name of the host that was queried.
\end{datadesc}
\begin{datadesc}{ip0}
\dataline{ip1}
\dataline{ip2}
\dataline{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.
1995-03-02 10:41:55 -04:00
\end{datadesc}
\begin{datadesc}{cpuType}
\dataline{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.
\end{datadesc}
\begin{datadesc}{exchange}
1998-03-16 22:02:51 -04:00
The name of a mail-exchanger host. Valid for ``mx'' queries.
1995-03-02 10:41:55 -04:00
\end{datadesc}
\begin{datadesc}{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.
1995-03-02 10:41:55 -04:00
\end{datadesc}
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}