Subprocess puzzle and two questions
Chris Angelico
rosuav at gmail.com
Wed Nov 14 16:54:29 EST 2012
On Thu, Nov 15, 2012 at 3:20 AM, Roy Smith <roy at panix.com> wrote:
> I wrote:
>>> Oh, my. You're using DNS as a replacement for ping? Fair enough. In
>>> that case, all you really care about is that you can connect to port 53
>>> on the server...
>>>
>>> s = socket.socket()
>>> s.connect(('8.8.8.8', 53))
>
> In article <mailman.3684.1352904008.27098.python-list at python.org>,
> Chris Angelico <rosuav at gmail.com> wrote:
>>That assumes that (a) the remote server supports TCP for DNS
>
> This is true. I honestly don't know what percentage of DNS servers
> out there only support UDP. The two I tried (Google's 8.8.8.8, and my
> Apple TimeCapsule) both supported TCP, but that's hardly a
> representitive sample.
I don't know either, all I know is that DNSReport recommends
supporting TCP, and none of my DNS servers ever fail that check.
>> and (b) that connection time for TCP is comparable to
>> ping or an actual DNS lookup.
>
> 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.
ChrisA
More information about the Python-list
mailing list