summaryrefslogtreecommitdiffstats
path: root/Doc/mac/libmacdnr.tex
blob: 2242e63a5a49780959ac712b3bd306a6fc119e8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
\section{\module{macdnr} ---
         Interfaces to the Macintosh Domain Name Resolver.}
\declaremodule{builtin}{macdnr}

\modulesynopsis{Interfaces to the Macintosh Domain Name Resolver.}


This module provides an interface to the Macintosh Domain Name
Resolver.  It is usually used in conjunction with the \module{mactcp}
module, to map hostnames to IP addresses.  It may not be available in
all Mac Python versions.
\index{Macintosh Domain Name Resolver}
\index{Domain Name Resolver, Macintosh}

The \module{macdnr} module defines the following functions:


\begin{funcdesc}{Open}{\optional{filename}}
Open the domain name resolver extension.  If \var{filename} is given it
should be the pathname of the extension, otherwise a default is
used.  Normally, this call is not needed since the other calls will
open the extension automatically.
\end{funcdesc}

\begin{funcdesc}{Close}{}
Close the resolver extension.  Again, not needed for normal use.
\end{funcdesc}

\begin{funcdesc}{StrToAddr}{hostname}
Look up the IP address for \var{hostname}.  This call returns a dnr
result object of the ``address'' variation.
\end{funcdesc}

\begin{funcdesc}{AddrToName}{addr}
Do a reverse lookup on the 32-bit integer IP-address
\var{addr}.  Returns a dnr result object of the ``address'' variation.
\end{funcdesc}

\begin{funcdesc}{AddrToStr}{addr}
Convert the 32-bit integer IP-address \var{addr} to a dotted-decimal
string.  Returns the string.
\end{funcdesc}

\begin{funcdesc}{HInfo}{hostname}
Query the nameservers for a \code{HInfo} record for host
\var{hostname}.  These records contain hardware and software
information about the machine in question (if they are available in
the first place).  Returns a dnr result object of the ``hinfo''
variety.
\end{funcdesc}

\begin{funcdesc}{MXInfo}{domain}
Query the nameservers for a mail exchanger for \var{domain}.  This is
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.
\end{funcdesc}

\subsection{dnr result object}
\label{dnr-result-object}

Since the DNR calls all execute asynchronously you do not get the
results back immediately.  Instead, you get a dnr result object.  You
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.

The \member{rtnCode} and \member{cname} attributes are always
available, the others depend on the type of query (address, hinfo or
mx).


% Add args, as in {arg1, arg2 \optional{, arg3}}
\begin{methoddesc}[dnr result]{wait}{}
Wait for the query to complete.
\end{methoddesc}

% Add args, as in {arg1, arg2 \optional{, arg3}}
\begin{methoddesc}[dnr result]{isdone}{}
Return \code{1} if the query is complete.
\end{methoddesc}


\begin{memberdesc}[dnr result]{rtnCode}
The error code returned by the query.
\end{memberdesc}

\begin{memberdesc}[dnr result]{cname}
The canonical name of the host that was queried.
\end{memberdesc}

\begin{memberdesc}[dnr result]{ip0}
\memberline[dnr result]{ip1}
\memberline[dnr result]{ip2}
\memberline[dnr result]{ip3}
At most four integer IP addresses for this host.  Unused entries are
zero.  Valid only for address queries.
\end{memberdesc}

\begin{memberdesc}[dnr result]{cpuType}
\memberline[dnr result]{osType}
Textual strings giving the machine type an OS name.  Valid for ``hinfo''
queries.
\end{memberdesc}

\begin{memberdesc}[dnr result]{exchange}
The name of a mail-exchanger host.  Valid for ``mx'' queries.
\end{memberdesc}

\begin{memberdesc}[dnr result]{preference}
The preference of this mx record.  Not too useful, since the Macintosh
will only return a single mx record.  Valid for ``mx'' queries only.
\end{memberdesc}

The simplest way to use the module to convert names to dotted-decimal
strings, without worrying about idle time, etc:
\begin{verbatim}
>>> def gethostname(name):
...     import macdnr
...     dnrr = macdnr.StrToAddr(name)
...     return macdnr.AddrToStr(dnrr.ip0)
\end{verbatim}