Re: Subprocess puzzle and two questions

2012-11-16 Thread Nobody
On Thu, 15 Nov 2012 20:07:38 -0500, Roy Smith wrote: >>> gethostbyname() and getaddrinfo() use the NSS (name-service switch) >> mechanism, which is configured via /etc/nsswitch.conf. Depending upon >> configuration, hostnames can be looked up via a plain text file >> (/etc/hosts), Berkeley DB file

Re: Subprocess puzzle and two questions

2012-11-15 Thread Roy Smith
In article , Nobody wrote: > That's because the high-level routines aren't tied to DNS. This is true. >> gethostbyname() and getaddrinfo() use the NSS (name-service switch) > mechanism, which is configured via /etc/nsswitch.conf. Depending upon > configuration, hostnames can be looked up via a

Re: Subprocess puzzle and two questions

2012-11-15 Thread Nobody
On Wed, 14 Nov 2012 20:49:19 -0500, Roy Smith wrote: >> I'm slightly surprised that there's no way with the Python stdlib to >> point a DNS query at a specific server > > Me too, including the "only slightly" part. The normal high-level C > resolver routines (getaddrinfo/getnameinfo, or even t

DNS from Python (was Re: Subprocess puzzle and two questions)

2012-11-14 Thread Aahz
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 don

Re: Subprocess puzzle and two questions

2012-11-14 Thread Kushal Kumaran
Chris Angelico writes: > On Thu, Nov 15, 2012 at 12:49 PM, Roy Smith wrote: >> In article , >> Chris Angelico wrote: >> >>> I'm slightly surprised that there's no way with the Python stdlib to >>> point a DNS query at a specific server >> >> Me too, including the "only slightly" part. The nor

Re: Subprocess puzzle and two questions

2012-11-14 Thread Dave Angel
On 11/14/2012 09:21 PM, Chris Angelico wrote: > On Thu, Nov 15, 2012 at 1:10 PM, Roy Smith wrote: >> In article , >> Chris Angelico wrote: >> >>> Indeed. But Python boasts that the batteries are included, and given >>> the wealth of other networking facilities that are available, it is a >>> bit

Re: Subprocess puzzle and two questions

2012-11-14 Thread Chris Angelico
On Thu, Nov 15, 2012 at 1:10 PM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> Indeed. But Python boasts that the batteries are included, and given >> the wealth of other networking facilities that are available, it is a >> bit of a hole that you can't run DNS queries in this way.

Re: Subprocess puzzle and two questions

2012-11-14 Thread Roy Smith
In article , Chris Angelico wrote: > Indeed. But Python boasts that the batteries are included, and given > the wealth of other networking facilities that are available, it is a > bit of a hole that you can't run DNS queries in this way. Think of the socket and struct modules as a pile of carbo

Re: Subprocess puzzle and two questions

2012-11-14 Thread Chris Angelico
On Thu, Nov 15, 2012 at 12:49 PM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> I'm slightly surprised that there's no way with the Python stdlib to >> point a DNS query at a specific server > > Me too, including the "only slightly" part. The normal high-level C > resolver routin

Re: Subprocess puzzle and two questions

2012-11-14 Thread Roy Smith
In article , Chris Angelico wrote: > I'm slightly surprised that there's no way with the Python stdlib to > point a DNS query at a specific server Me too, including the "only slightly" part. The normal high-level C resolver routines (getaddrinfo/getnameinfo, or even the old gethostbyname se

Re: Subprocess puzzle and two questions

2012-11-14 Thread Chris Angelico
On Thu, Nov 15, 2012 at 3:20 AM, Roy Smith 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

Re: Subprocess puzzle and two questions

2012-11-14 Thread Roy Smith
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 , Chris Angelico wrote: >That assumes that (a) the

Re: Subprocess puzzle and two questions

2012-11-14 Thread wrw
On Nov 14, 2012, at 9:22 AM, Roy Smith wrote: > In article , > William Ray Wing wrote: > >> On Nov 13, 2012, at 11:41 PM, Roy Smith wrote: >> >>> In article , >>> w...@mac.com wrote: >>> I need to time the operation of a command-line utility (specifically nslookup) from within a p

Re: Subprocess puzzle and two questions

2012-11-14 Thread Chris Angelico
On Thu, Nov 15, 2012 at 1:22 AM, Roy Smith 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... > > import socket > import time > s = socket.socket() > t0 = time.time() > s.conne

Re: Subprocess puzzle and two questions

2012-11-14 Thread Roy Smith
In article , William Ray Wing wrote: > On Nov 13, 2012, at 11:41 PM, Roy Smith wrote: > > > In article , > > w...@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 d

Re: Subprocess puzzle and two questions

2012-11-13 Thread Tim Roberts
w...@mac.com wrote: >... >However, if I try the same operation in the python interpreter using >subprocess.Popen like so: > import subprocess result = subprocess.Popen(['time', 'nslookup', 'www.es.net', '8.8.4.4'], shell = False, stdout = subprocess.PIPE, stderr = subprocess.

Re: Subprocess puzzle and two questions

2012-11-13 Thread Kushal Kumaran
w...@mac.com writes: > I need to time the operation of a command-line utility (specifically > nslookup) from within a python program I'm writing. I don't want to use > python's timeit function because I'd like to avoid python's subprocess > creation overhead. That leads me to the standard UNI

Re: Subprocess puzzle and two questions

2012-11-13 Thread William Ray Wing
On Nov 13, 2012, at 11:41 PM, Roy Smith wrote: > In article , > w...@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 > s

Re: Subprocess puzzle and two questions

2012-11-13 Thread Roy Smith
In article , w...@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

Subprocess puzzle and two questions

2012-11-13 Thread wrw
I need to time the operation of a command-line utility (specifically nslookup) from within a python program I'm writing. I don't want to use python's timeit function because I'd like to avoid python's subprocess creation overhead. That leads me to the standard UNIX time function. So for examp