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 |
Fred Drake | af5c0fc | 1998-03-17 02:02:51 +0000 | [diff] [blame^] | 6 | Resolver. It is usually used in conjunction with the \module{mactcp} |
Guido van Rossum | 96628a9 | 1995-04-10 11:34:00 +0000 | [diff] [blame] | 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 | |
Fred Drake | af5c0fc | 1998-03-17 02:02:51 +0000 | [diff] [blame^] | 10 | The \module{macdnr} module defines the following functions: |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 11 | |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 12 | |
| 13 | \begin{funcdesc}{Open}{\optional{filename}} |
Guido van Rossum | 96628a9 | 1995-04-10 11:34:00 +0000 | [diff] [blame] | 14 | Open the domain name resolver extension. If \var{filename} is given it |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 15 | should be the pathname of the extension, otherwise a default is |
Guido van Rossum | 96628a9 | 1995-04-10 11:34:00 +0000 | [diff] [blame] | 16 | used. Normally, this call is not needed since the other calls will |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 17 | open the extension automatically. |
| 18 | \end{funcdesc} |
| 19 | |
| 20 | \begin{funcdesc}{Close}{} |
Guido van Rossum | 96628a9 | 1995-04-10 11:34:00 +0000 | [diff] [blame] | 21 | Close the resolver extension. Again, not needed for normal use. |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 22 | \end{funcdesc} |
| 23 | |
| 24 | \begin{funcdesc}{StrToAddr}{hostname} |
Guido van Rossum | 96628a9 | 1995-04-10 11:34:00 +0000 | [diff] [blame] | 25 | 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] | 26 | result object of the ``address'' variation. |
| 27 | \end{funcdesc} |
| 28 | |
| 29 | \begin{funcdesc}{AddrToName}{addr} |
| 30 | Do a reverse lookup on the 32-bit integer IP-address |
Guido van Rossum | 96628a9 | 1995-04-10 11:34:00 +0000 | [diff] [blame] | 31 | \var{addr}. Returns a dnr result object of the ``address'' variation. |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 32 | \end{funcdesc} |
| 33 | |
| 34 | \begin{funcdesc}{AddrToStr}{addr} |
| 35 | 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] | 36 | string. Returns the string. |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 37 | \end{funcdesc} |
| 38 | |
| 39 | \begin{funcdesc}{HInfo}{hostname} |
| 40 | Query the nameservers for a \code{HInfo} record for host |
Guido van Rossum | 96628a9 | 1995-04-10 11:34:00 +0000 | [diff] [blame] | 41 | \var{hostname}. These records contain hardware and software |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 42 | information about the machine in question (if they are available in |
Guido van Rossum | 96628a9 | 1995-04-10 11:34:00 +0000 | [diff] [blame] | 43 | the first place). Returns a dnr result object of the ``hinfo'' |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 44 | variety. |
| 45 | \end{funcdesc} |
| 46 | |
| 47 | \begin{funcdesc}{MXInfo}{domain} |
Guido van Rossum | 96628a9 | 1995-04-10 11:34:00 +0000 | [diff] [blame] | 48 | Query the nameservers for a mail exchanger for \var{domain}. This is |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 49 | 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] | 50 | domain. Returns a dnr result object of the ``mx'' variety. |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 51 | \end{funcdesc} |
| 52 | |
| 53 | \subsection{dnr result object} |
| 54 | |
| 55 | 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] | 56 | results back immediately. Instead, you get a dnr result object. You |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 57 | can check this object to see whether the query is complete, and access |
| 58 | its attributes to obtain the information when it is. |
| 59 | |
| 60 | Alternatively, you can also reference the result attributes directly, |
| 61 | this will result in an implicit wait for the query to complete. |
| 62 | |
Fred Drake | af5c0fc | 1998-03-17 02:02:51 +0000 | [diff] [blame^] | 63 | The \member{rtnCode} and \member{cname} attributes are always |
| 64 | available, the others depend on the type of query (address, hinfo or |
| 65 | mx). |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 66 | |
Fred Drake | af5c0fc | 1998-03-17 02:02:51 +0000 | [diff] [blame^] | 67 | \setindexsubitem{(dnr result method)} |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 68 | |
Fred Drake | af5c0fc | 1998-03-17 02:02:51 +0000 | [diff] [blame^] | 69 | % Add args, as in {arg1, arg2 \optional{, arg3}} |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 70 | \begin{funcdesc}{wait}{} |
| 71 | Wait for the query to complete. |
| 72 | \end{funcdesc} |
| 73 | |
Fred Drake | af5c0fc | 1998-03-17 02:02:51 +0000 | [diff] [blame^] | 74 | % Add args, as in {arg1, arg2 \optional{, arg3}} |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 75 | \begin{funcdesc}{isdone}{} |
Fred Drake | af5c0fc | 1998-03-17 02:02:51 +0000 | [diff] [blame^] | 76 | Return \code{1} if the query is complete. |
Jack Jansen | f16d5fa | 1995-03-02 14:41:55 +0000 | [diff] [blame] | 77 | \end{funcdesc} |
| 78 | |
Fred Drake | af5c0fc | 1998-03-17 02:02:51 +0000 | [diff] [blame^] | 79 | \setindexsubitem{(dnr result 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} |
Fred Drake | af5c0fc | 1998-03-17 02:02:51 +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} |
Fred Drake | af5c0fc | 1998-03-17 02:02:51 +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 |
Fred Drake | af5c0fc | 1998-03-17 02:02:51 +0000 | [diff] [blame^] | 109 | will only return a single mx record. Valid for ``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} |