Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion DNS from Python (was Re: Subprocess puzzle and two questions)

Received: by 10.66.81.200 with SMTP id c8mr16563pay.1.1352958179063;
        Wed, 14 Nov 2012 21:42:59 -0800 (PST)
MIME-Version: 1.0
Path: s9ni12013pbb.0!nntp.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!news.glorb.com!news-out.readnews.com!transit4.readnews.com!panix!panix5.panix.com!not-for-mail
From: a...@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: <k81vd2$aoi$1@panix5.panix.com>
References: <mailman.3664.1352867713.27098.python-list@python.org> <mailman.3684.1352904008.27098.python-list@python.org> <k80gd6$t0q$1@panix2.panix.com> <mailman.3700.1352930072.27098.python-list@python.org>
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)
X-Received-Bytes: 2404

In article <mailman.3700.1352930072.27098.python-l...@python.org>,
Chris Angelico  <ros...@gmail.com> wrote:
>On Thu, Nov 15, 2012 at 3:20 AM, Roy Smith <r...@panix.com> 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 (a...@pythoncraft.com)           <*>         http://www.pythoncraft.com/

"LL YR VWL R BLNG T S"  -- www.nancybuttons.com