andrew-pythonlist at puzzling.org
Mon Jun 16 10:55:22 CEST 2003
On Mon, Jun 16, 2003 at 07:43:02AM +0000, Chris White wrote:
> Well, I tried the python-dns module that exists out there, but it's not
> working so for.
> It would be nice if there was a socket function to pull up info about mx
> servers for a domain name. If anyone knows a working with (yes, here it
> comes) windoze operating system that simply uses the default nameserver or
> lets me set it for that matter (the later would be more prefered, as it
> would make it more cross platform compatible IMHO).
> Also, if anyone knows some good easy to understand (snicker) RFC's for DNS
> Querying (or some page that breaks it down) that would be great as well.
It's probably overkill, but you can do it with Twisted:
---- mxquery.py ----
"""Command-line util for resolving MXs.
mxquery.py example.com # Uses DNS servers in /etc/resolv.conf
mxquery.py example.com 126.96.36.199 # Uses DNS server 188.8.131.52
Adapted from doc/examples/dns-service.py in the Twisted distribution.
from twisted.names import client
from twisted.internet import reactor
def printAnswer((answers, auth, add)):
if not len(answers):
print 'No answers'
print '\n'.join([str(x.payload) for x in answers])
print "error: could not resolve:", arg
if len(sys.argv) not in (2,3):
sys.stderr.write('%s: usage:\n' % sys.argv +
' %s domain [dns server]\n' % sys.argv)
domain = sys.argv
if len(sys.argv) == 2:
resolver = client.Resolver('/etc/resolv.conf')
resolver = client.Resolver(servers=[(sys.argv,53)])
d = resolver.lookupMailExchange('%s' % (domain,), )
More information about the Python-list