Subprocess puzzle and two questions
wrw at mac.com
wrw at mac.com
Wed Nov 14 09:37:12 EST 2012
On Nov 14, 2012, at 9:22 AM, Roy Smith <roy at panix.com> wrote:
> In article <mailman.3666.1352873042.27098.python-list at python.org>,
> William Ray Wing <wrw at mac.com> wrote:
>
>> On Nov 13, 2012, at 11:41 PM, Roy Smith <roy at panix.com> wrote:
>>
>>> In article <mailman.3664.1352867713.27098.python-list at python.org>,
>>> wrw at mac.com wrote:
>>>
>>>> I need to time the operation of a command-line utility (specifically
>>>> nslookup) from within a python program I'm writing.
>>>
>>> Ugh. Why are you doing this? Shelling out to nslookup is an incredibly
>>> slow and clumsy way of doing name translation. What you really want to
>>> be doing is calling getaddrinfo() directly.
>>>
>>> See http://docs.python.org/2/library/socket.html#socket.getaddrinfo for
>>> details.
>>> --
>> Because, unless I'm badly mistaken (very possible), getaddrinfo doesn't let
>> me specify the server from which the name is returned. I'm really not after
>> the name, what I'm REALLY after is the fact that a path exists to the name
>> server I specify (and how long it takes to respond). In the "good old days" I
>> would just have ping'd it, but these days more and more DNS boxes (and
>> servers of all sorts) are shutting off their ping response.
>>
>> Thanks, Bill
>
> 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...
>
> import socket
> import time
> s = socket.socket()
> t0 = time.time()
> s.connect(('8.8.8.8', 53))
> t1 = time.time()
> print "it took %f seconds to connect" % (t1 - t0)
> --
> http://mail.python.org/mailman/listinfo/python-list
Now THAT looks better. Simpler, cleaner, (longer, taller, stronger, faster, cheaper… :-)
Thanks,
Bill
More information about the Python-list
mailing list