Guido van Rossum | 470be14 | 1995-03-17 16:07:09 +0000 | [diff] [blame] | 1 | \section{Built-in Module \sectcode{macdnr}} |
Guido van Rossum | e47da0a | 1997-07-17 16:34:52 +0000 | [diff] [blame] | 2 | \label{module-macdnr} |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 3 | \bimodindex{macdnr} |
| 4 | |
| 5 | This module provides an interface to the Macintosh Domain Name |
Guido van Rossum | 96628a9 | 1995-04-10 11:34:00 +0000 | [diff] [blame] | 6 | Resolver. It is usually used in conjunction with the \var{mactcp} |
| 7 | module, to map hostnames to IP-addresses. It may not be available in |
| 8 | all Mac Python versions. |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 9 | |
| 10 | The \code{macdnr} module defines the following functions: |
| 11 | |
Fred Drake | 1947991 | 1998-02-13 06:58:54 +0000 | [diff] [blame] | 12 | \setindexsubitem{(in module macdnr)} |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 13 | |
| 14 | \begin{funcdesc}{Open}{\optional{filename}} |
Guido van Rossum | 96628a9 | 1995-04-10 11:34:00 +0000 | [diff] [blame] | 15 | Open the domain name resolver extension. If \var{filename} is given it |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 16 | should be the pathname of the extension, otherwise a default is |
Guido van Rossum | 96628a9 | 1995-04-10 11:34:00 +0000 | [diff] [blame] | 17 | used. Normally, this call is not needed since the other calls will |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 18 | open the extension automatically. |
| 19 | \end{funcdesc} |
| 20 | |
| 21 | \begin{funcdesc}{Close}{} |
Guido van Rossum | 96628a9 | 1995-04-10 11:34:00 +0000 | [diff] [blame] | 22 | Close the resolver extension. Again, not needed for normal use. |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 23 | \end{funcdesc} |
| 24 | |
| 25 | \begin{funcdesc}{StrToAddr}{hostname} |
Guido van Rossum | 96628a9 | 1995-04-10 11:34:00 +0000 | [diff] [blame] | 26 | Look up the IP address for \var{hostname}. This call returns a dnr |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 27 | result object of the ``address'' variation. |
| 28 | \end{funcdesc} |
| 29 | |
| 30 | \begin{funcdesc}{AddrToName}{addr} |
| 31 | Do a reverse lookup on the 32-bit integer IP-address |
Guido van Rossum | 96628a9 | 1995-04-10 11:34:00 +0000 | [diff] [blame] | 32 | \var{addr}. Returns a dnr result object of the ``address'' variation. |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 33 | \end{funcdesc} |
| 34 | |
| 35 | \begin{funcdesc}{AddrToStr}{addr} |
| 36 | Convert the 32-bit integer IP-address \var{addr} to a dotted-decimal |
Guido van Rossum | 96628a9 | 1995-04-10 11:34:00 +0000 | [diff] [blame] | 37 | string. Returns the string. |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 38 | \end{funcdesc} |
| 39 | |
| 40 | \begin{funcdesc}{HInfo}{hostname} |
| 41 | Query the nameservers for a \code{HInfo} record for host |
Guido van Rossum | 96628a9 | 1995-04-10 11:34:00 +0000 | [diff] [blame] | 42 | \var{hostname}. These records contain hardware and software |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 43 | information about the machine in question (if they are available in |
Guido van Rossum | 96628a9 | 1995-04-10 11:34:00 +0000 | [diff] [blame] | 44 | the first place). Returns a dnr result object of the ``hinfo'' |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 45 | variety. |
| 46 | \end{funcdesc} |
| 47 | |
| 48 | \begin{funcdesc}{MXInfo}{domain} |
Guido van Rossum | 96628a9 | 1995-04-10 11:34:00 +0000 | [diff] [blame] | 49 | Query the nameservers for a mail exchanger for \var{domain}. This is |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 50 | the hostname of a host willing to accept SMTP mail for the given |
Guido van Rossum | 96628a9 | 1995-04-10 11:34:00 +0000 | [diff] [blame] | 51 | domain. Returns a dnr result object of the ``mx'' variety. |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 52 | \end{funcdesc} |
| 53 | |
| 54 | \subsection{dnr result object} |
| 55 | |
| 56 | Since the DNR calls all execute asynchronously you do not get the |
Guido van Rossum | 96628a9 | 1995-04-10 11:34:00 +0000 | [diff] [blame] | 57 | results back immediately. Instead, you get a dnr result object. You |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 58 | can check this object to see whether the query is complete, and access |
| 59 | its attributes to obtain the information when it is. |
| 60 | |
| 61 | Alternatively, you can also reference the result attributes directly, |
| 62 | this will result in an implicit wait for the query to complete. |
| 63 | |
| 64 | The \var{rtnCode} and \var{cname} attributes are always available, the |
| 65 | others depend on the type of query (address, hinfo or mx). |
| 66 | |
Fred Drake | 1947991 | 1998-02-13 06:58:54 +0000 | [diff] [blame] | 67 | \setindexsubitem{(dnr result object method)} |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 68 | |
| 69 | % Add args, as in {arg1\, arg2 \optional{\, arg3}} |
| 70 | \begin{funcdesc}{wait}{} |
| 71 | Wait for the query to complete. |
| 72 | \end{funcdesc} |
| 73 | |
| 74 | % Add args, as in {arg1\, arg2 \optional{\, arg3}} |
| 75 | \begin{funcdesc}{isdone}{} |
| 76 | Return 1 if the query is complete. |
| 77 | \end{funcdesc} |
| 78 | |
Fred Drake | 1947991 | 1998-02-13 06:58:54 +0000 | [diff] [blame] | 79 | \setindexsubitem{(dnr result object attribute)} |
Guido van Rossum | 470be14 | 1995-03-17 16:07:09 +0000 | [diff] [blame] | 80 | |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 81 | \begin{datadesc}{rtnCode} |
| 82 | The error code returned by the query. |
| 83 | \end{datadesc} |
| 84 | |
| 85 | \begin{datadesc}{cname} |
| 86 | The canonical name of the host that was queried. |
| 87 | \end{datadesc} |
| 88 | |
| 89 | \begin{datadesc}{ip0} |
| 90 | \dataline{ip1} |
| 91 | \dataline{ip2} |
| 92 | \dataline{ip3} |
Guido van Rossum | 96628a9 | 1995-04-10 11:34:00 +0000 | [diff] [blame] | 93 | At most four integer IP addresses for this host. Unused entries are |
| 94 | zero. Valid only for address queries. |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 95 | \end{datadesc} |
| 96 | |
| 97 | \begin{datadesc}{cpuType} |
| 98 | \dataline{osType} |
Guido van Rossum | 96628a9 | 1995-04-10 11:34:00 +0000 | [diff] [blame] | 99 | Textual strings giving the machine type an OS name. Valid for hinfo |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 100 | queries. |
| 101 | \end{datadesc} |
| 102 | |
| 103 | \begin{datadesc}{exchange} |
Guido van Rossum | 96628a9 | 1995-04-10 11:34:00 +0000 | [diff] [blame] | 104 | The name of a mail-exchanger host. Valid for mx queries. |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 105 | \end{datadesc} |
| 106 | |
| 107 | \begin{datadesc}{preference} |
Guido van Rossum | 96628a9 | 1995-04-10 11:34:00 +0000 | [diff] [blame] | 108 | The preference of this mx record. Not too useful, since the Macintosh |
| 109 | will only return a single mx record. Mx queries only. |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 110 | \end{datadesc} |
| 111 | |
| 112 | The simplest way to use the module to convert names to dotted-decimal |
| 113 | strings, without worrying about idle time, etc: |
Fred Drake | 1947991 | 1998-02-13 06:58:54 +0000 | [diff] [blame] | 114 | \begin{verbatim} |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 115 | >>> def gethostname(name): |
| 116 | ... import macdnr |
| 117 | ... dnrr = macdnr.StrToAddr(name) |
| 118 | ... return macdnr.AddrToStr(dnrr.ip0) |
Fred Drake | 1947991 | 1998-02-13 06:58:54 +0000 | [diff] [blame] | 119 | \end{verbatim} |