Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-out.readnews.com!transit4.readnews.com!panix!panix5.panix.com!not-for-mail From: aahz@pythoncraft.com (Aahz) Newsgroups: comp.lang.python Subject: DNS from Python (was Re: Subprocess puzzle and two questions) Date: 14 Nov 2012 21:42:58 -0800 Organization: The Cat & Dragon Lines: 32 Message-ID: References: NNTP-Posting-Host: panix5.panix.com X-Trace: reader1.panix.com 1352958178 1889 166.84.1.5 (15 Nov 2012 05:42:58 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Thu, 15 Nov 2012 05:42:58 +0000 (UTC) Xref: csiph.com comp.lang.python:33372 In article , Chris Angelico wrote: >On Thu, Nov 15, 2012 at 3:20 AM, Roy Smith wrote: >> >> My first thought to solve both of these is that it shouldn't be too >> hard to hand-craft a minimal DNS query and send it over UDP. Then, I >> hunted around a bit and found that somebody had already done that, in >> spades. Take a look at http://www.dnspython.org; it might be exactly >> what's needed here. > >Yeah, that sounds like a good option. I'm slightly surprised that >there's no way with the Python stdlib to point a DNS query at a >specific server, but dnspython might be the solution. On the flip >side, dnspython is dauntingly large; it looks like a full >implementation of DNS, but I don't see a simple entrypoint that wraps >it all up into a simple function that can be bracketed with >time.time() calls (granted, I only skimmed the docs VERY quickly). So >it may be simpler to hand-craft an outgoing UDP packet once, save it >as a string literal, send that, and just wait for any response. That >eliminates all DNS protocolling and just times the round trip. From one of my scripts lying around: domain = MAILTO.split('@',1)[1] server = str(dns.resolver.query(domain, 'MX')[0].exchange) You'll need to play around a bit to find out what that does, but it should point you in the right direction. -- Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/ "LL YR VWL R BLNG T S" -- www.nancybuttons.com