And you thought the adns docs were sparse.

To build: First, you gotta have the adns libraries installed somewhere.

http://www.chiark.greenend.org.uk/~ian/adns/

Second, you gotta have Distutils, which comes in Python 1.6 and up. If you
have Python 1.5.2, get Distutils from:

http://www.python.org/sigs/distutils-sig/download.html

Then, you can build and install:

$ python setup.py build
# python setup.py install

Other useful things:

$ python setup.py bdist # make a binary distribution
$ python setup.py bdist_rpm # make an RPM

RTFM for Distutils for more options.

Usage:

See the included test programs for examples. A simple interactive
example that uses synchronous queries:

>>> import adns
>>> s=adns.init()
>>> s.synchronous('comstar.net',adns.rr.MX)
(0, None, 952395198, ((10, ('mx00.comstar.net', 0, ((2, '207.15.208.210'),))), (20, ('mx.comstar.net', 0, ((2, '207.15.208.210'), (2, '207.15.208.211'))))))
>>>

Results are generally returned as a 4-tuple: status, CNAME, expires, answer

status is the adns status, enumerated in adns.status.

CNAME is the CNAME of the answer, if any (None if the query target is not a
CNAME)

expires is the time (in ticks) that the answer's TTL expires.

answer is what you really want. Since queries generally can return more than
one answer, answer is returned as an n-tuple. The format of each item in the
tuple depends on what type of RR was requested.

>>> s.synchronous('comstar.net',adns.rr.MXraw)
(0, None, 952395198, ((10, 'mx00.comstar.net'), (20, 'mx.comstar.net')))

In this case, MXraw returns only the MX data (priority and hostname). MX
does further expansions upon the hostname, returning a tuple of hostname,
status for the following data, and then a tuple of rr.ADDR answers, which
are the address class and the IP address, i.e.

>>> s.synchronous('mx00.comstar.net',adns.rr.ADDR)
(0, None, 952354985, ((2, '207.15.208.210'),))
>>> s.synchronous('mx.comstar.net',adns.rr.ADDR)
(0, None, 952385003, ((2, '207.15.208.210'), (2, '207.15.208.211')))

and compare to:

>>> s.synchronous('mx00.comstar.net',adns.rr.A)
(0, None, 952354985, ('207.15.208.210',))
>>> s.synchronous('mx.comstar.net',adns.rr.A)
(0, None, 952385003, ('207.15.208.211', '207.15.208.210'))

Prefer to use exceptions to processing status codes? adns.exception(status)
will raise an appropriate exception. Sometimes you need to have the result,
even when there is an exceptional condition. The exceptions are:

Error
  +- NotReadyError
  +- LocalError
  +- RemoteError
  |    +- RemoteFailureError
  |    +- RemoteTempError
  +- QueryError
  +- PermanentError
       +- NXDomain
       +- NoData

For asynchronous examples, see ADNS.py, hostmx.py, and rblcheck.py.

Despite the low version number, I have been using this library in production
code (very heavy use on mail servers) for more than a year and it is quite
stable. It has been tested with adns-1.0.

adns uses the GPL license, so now adns-python does too. Or you can use the
original license, which is also a free software license based on the Python
1.5.2 license.

Andy Dustman
<andy@dustman.net>
November 30, 2000
