Python 3 DNS library
Release 4.0.0 UNRELEASED
Removed class DnsAsyncRequest since Python 3.12 dropped asyncore. Bumping
major version since this is a breaking change. If you need async DNS, use
Changed behavior when /etc/resolv.conf is missing. Instead of
FileNotFoundError, assume DNS server is '127.0.0.1'.
Release 3.2.0 Mon Jul 23 2018
Switched from distutils to setuptools because "it's the future". It is
unlikely to have end user impact. For python3.3+ no additional dependencies
Release 3.1.0 Thu Apr 24 23:52:00 EDT 2014
More choices about result types are provided in 3.1.0. To specify resulttype,
in a DnsRequest object, use the new function DnsRequest.qry
(resulttype='binary/text/default'). DnsRequest.qry returns ipaddress objects
for A and AAAA queries by defaults. Other defaults are the same as
DnsRequest.req. Continue to use DnsRequest.req for exact backward
compatibility with pydns and older py3dns defaults. TXT and SPF record data
are returned as strings by default, this matches what dnspython3 returns.
The ipaddress module is used internally now. See CHANGES for details.
Release 3.0.3 Wed May 29 00:05:00 EDT 2013
There was a third, unintended incompatiblity in 3.0.2 in that IPv6 addresses
were returned in their string format rather than their decimal format. This
breaks pyspf queries when the connect IP is IPv6. 3.0.3 is a release strictly
to revert this change.
Release 3.0.2 Thu Jan 19 01:25:00 EST 2012
This release introduces two potentially incompatible changes from the python
verion of DNS (pydns). First, the data portion of DNS records of types TXT
and SPF are returned as bytes instead of strings. Second, additional sub
classes of DNSError have been added. Any code that catches DNSError should
be checked to see if it needs updating to catch one of the new sub classes:
ArgumentError, SocketError, TimeoutError, ServerError, and
Release 3.0 Sun Mar 2-9 23:07:22 2011 -0400
Ported to Python3 by Scott Kitterman <firstname.lastname@example.org>. This is mostly a
minimal port to work with Python3 (tested with python3.2) plus addition of
some of the patches that people have submitted on Sourceforge. It should be
fully API compatible with 2.3. Note: Version 3.0.0 shipped with a new
lazy.lookupfull function in advance of 2.3. This was incorporated in pydns
2.3.5 as lazy.lookupalll. It has been renamed in 3.0.1 to stay API compatible
with pydns 2.3.
Release 2.3 Mon May 6 16:18:02 EST 2002
This is a another release of the pydns code, as originally written by
Guido van Rossum, and with a hopefully nicer API bolted over the
top of it by Anthony Baxter <email@example.com>.
This code is released under a Python-style license.
I'm making this release because there hasn't been a release in a
heck of a long time, and it probably deserves one. I'd also like to
do a substantial refactor of some of the guts of the code, and this
is likely to break any code that uses the existing interface. So
this will be a release for people who are using the existing API...
There are several known bugs/unfinished bits
- processing of AXFR results is not done yet.
- doesn't do IPv6 DNS requests (type AAAA)
- docs, aside from this file
- all sorts of other stuff that I've probably forgotten.
- MacOS support for discovering nameservers
- the API that I evolved some time ago is pretty ugly. I'm going
to re-do it, designed this time.
Stuff it _does_ do:
- processes /etc/resolv.conf - at least as far as nameserver directives go.
- tries multiple nameservers.
- nicer API - see below.
- returns results in more useful format.
- optional timing of requests.
- default 'show' behaviour emulates 'dig' pretty closely.
args can be a name, in which case it takes that as the query, and/or a series
of keyword/value args. (see below for a list of args)
when calling the 'req()' method, it reuses the options specified in the
DNS.Request() call as defaults.
options are applied in the following order:
those specified in the req() call
or, if not specified there,
those specified in the creation of the Request() object
or, if not specified there,
those specified in the DNS.defaults dictionary
name servers can be specified in the following ways:
- by calling DNS.DiscoverNameServers(), which will load the DNS servers
from the system's /etc/resolv.conf file on Unix, or from the Registry
- by specifying it as an option to the request
- by manually setting DNS.defaults['server'] to a list of server IP
addresses to try
- XXXX It should be possible to load the DNS servers on a mac os machine,
from where-ever they've squirrelled them away
name="host.do.main" # the object being looked up
qtype="SOA" # the query type, eg SOA, A, MX, CNAME, ANY
protocol="udp" # "udp" or "tcp" - usually you want "udp"
server="nameserver" # the name of the nameserver. Note that you might
# want to use an IP address here
rd=1 # "recursion desired" - defaults to 1.
other: opcode, port, ...
There's also some convenience functions, for the lazy:
to do a reverse lookup:
>>> print DNS.revlookup("184.108.40.206")
to look up all MX records for an entry:
>>> print DNS.mxlookup("connect.com.au")
[(10, 'yarrina.connect.com.au'), (100, 'warrane.connect.com.au')]
Documentation of the rest of the interface will have to wait for a
later date. Note that the DnsAsyncRequest stuff is currently not
working - I haven't looked too closely at why, yet.
There's some examples in the tests/ directory - including test5.py,
which is even vaguely useful. It looks for the SOA for a domain, checks
that the primary NS is authoritative, then checks the nameservers
that it believes are NSs for the domain and checks that they're
authoritative, and that the zone serial numbers match.
see also README.guido for the original docs.
py3dns is derived from pydns. The sourceforge details below refer to pydns.
All py3dns issues/comments/etc should be reported via
comments to me, firstname.lastname@example.org, or to the mailing list,
bugs/patches to the tracker on SF -
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.