[Python-Dev] Proposed DNS query library
Bob Halley
halley@play-bow.org
28 Jun 2003 20:15:10 -0700
"John D." <lists@webcrunchers.com> writes:
> Python has everything else, but it doesn't have a nameserver lookup
> class. I propose creating a library which will perform the
> equivalent of the "dig" or "nslookup" commands. My own application
> is using it to query a DNS for mx records as a preface to using
> smtplib. (Perhaps this should be added to smtplib?)
> Is this a good idea or do I need to spend more time in the oven?
> (or worse, it already exists and I overlooked it?)
My dnspython package ( http://www.dnspython.org ) can do this, and a
lot more. Here's a program which gets and prints MX records.
import dns.resolver
answers = dns.resolver.query('dnspython.org', 'MX')
for rdata in answers:
print 'Host', rdata.exchange, 'has preference', rdata.preference
/Bob