Subprocess puzzle and two questions
Nobody
nobody at nowhere.com
Thu Nov 15 17:54:10 EST 2012
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 the old
> gethostbyname series), don't expose any way to do that.
That's because the high-level routines aren't tied to DNS.
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 files, DNS, NIS, NIS+, LDAP, WINS, etc. DNS is
just one particular back-end, which may or may not be used on any given
system.
If you specifically want to perform DNS queries, you have to use a
DNS-specific interface (e.g. the res_* functions described in the
resolver(3) manpage), or raw sockets, rather than a high-level interface
such as gethostbyname() or getaddrinfo().
More information about the Python-list
mailing list