Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #55062 > unrolled thread

DNS query against a specific server.

Started byMichel Albert <exhuma@gmail.com>
First post2013-09-30 04:42 -0700
Last post2013-09-30 06:04 -0700
Articles 7 — 5 participants

Back to article view | Back to comp.lang.python


Contents

  DNS query against a specific server. Michel Albert <exhuma@gmail.com> - 2013-09-30 04:42 -0700
    Re: DNS query against a specific server. William Ray Wing <wrw@mac.com> - 2013-09-30 08:36 -0400
      Re: DNS query against a specific server. Michel Albert <exhuma@gmail.com> - 2013-09-30 05:45 -0700
        Re: DNS query against a specific server. Chris Angelico <rosuav@gmail.com> - 2013-09-30 22:56 +1000
        Re: DNS query against a specific server. "Gisle Vanem" <gvanem@yahoo.no> - 2013-09-30 15:35 +0200
    Re: DNS query against a specific server. Ervin Hegedüs <airween@gmail.com> - 2013-09-30 14:54 +0200
      Re: DNS query against a specific server. Michel Albert <exhuma@gmail.com> - 2013-09-30 06:04 -0700

#55062 — DNS query against a specific server.

FromMichel Albert <exhuma@gmail.com>
Date2013-09-30 04:42 -0700
SubjectDNS query against a specific server.
Message-ID<634fa158-1d15-4a7e-ac0f-7a3f57f55cc7@googlegroups.com>
Hi,

``socket.gethostbyname`` sends the DNS resolution query to the DNS server specified by the OS. Is there an easy way to send a query to a *different* server?

I see that twisted.names allows you to do this, but, having all of twisted as dependency to my project when all I need to do is a simple DNS query seems a bit extreme. I also found pydns, but that looks fairly outdated and unmaintained.

Is there not an actively maintained lightweight solution? If not, I will go with twisted.


Cheers,
Mich.

[toc] | [next] | [standalone]


#55065

FromWilliam Ray Wing <wrw@mac.com>
Date2013-09-30 08:36 -0400
Message-ID<mailman.481.1380544612.18130.python-list@python.org>
In reply to#55062
On Sep 30, 2013, at 7:42 AM, Michel Albert <exhuma@gmail.com> wrote:

> Hi,
> 
> ``socket.gethostbyname`` sends the DNS resolution query to the DNS server specified by the OS. Is there an easy way to send a query to a *different* server?
> 
> I see that twisted.names allows you to do this, but, having all of twisted as dependency to my project when all I need to do is a simple DNS query seems a bit extreme. I also found pydns, but that looks fairly outdated and unmaintained.
> 
> Is there not an actively maintained lightweight solution? If not, I will go with twisted.
> 
> 
> Cheers,
> Mich.
> -- 
> https://mail.python.org/mailman/listinfo/python-list

It isn't pure python, but you would be pretty much guaranteed a maintained solution if you use the name server lookup in your OS.  Something like:

	import subprocess
	nsl_reslt = subprocess.Popen(['nslookup', '<insert name nere>' ],stderr = subprocess.PIPE, stdout = subprocess.PIPE).communicate()[0]


Hope this helps,
Bill

[toc] | [prev] | [next] | [standalone]


#55067

FromMichel Albert <exhuma@gmail.com>
Date2013-09-30 05:45 -0700
Message-ID<e76f9cfa-c8ad-4eee-86e3-1f0a0bffe646@googlegroups.com>
In reply to#55065
On Monday, 30 September 2013 14:36:34 UTC+2, William Ray Wing  wrote:
> On Sep 30, 2013, at 7:42 AM, Michel Albert <***> wrote:
> 
> 
> 
> > Hi,
> 
> > 
> 
> > ``socket.gethostbyname`` sends the DNS resolution query to the DNS server specified by the OS. Is there an easy way to send a query to a *different* server?
> 
> > 
> 
> > I see that twisted.names allows you to do this, but, having all of twisted as dependency to my project when all I need to do is a simple DNS query seems a bit extreme. I also found pydns, but that looks fairly outdated and unmaintained.
> 
> > 
> 
> > Is there not an actively maintained lightweight solution? If not, I will go with twisted.
> 
> > 
> 
> > 
> 
> > Cheers,
> 
> > Mich.
> 
> > -- 
> 
> > https://mail.python.org/mailman/listinfo/python-list
> 
> 
> 
> It isn't pure python, but you would be pretty much guaranteed a maintained solution if you use the name server lookup in your OS.  Something like:
> 
> 
> 
> 	import subprocess
> 
> 	nsl_reslt = subprocess.Popen(['nslookup', '<insert name nere>' ],stderr = subprocess.PIPE, stdout = subprocess.PIPE).communicate()[0]
> 
> 
> 
> 
> 
> Hope this helps,
> 
> Bill

Hmm... I had this option in mind, but opening a subprocess for something as small as this seemed a bit error-prone. If something on the system changes, nslookup replaced by dig or nslookup output changes for example your application will bug out.

Granted, the chance of this happening is slim, but using a fixed-version dependency in your setup script gives you a much safer solution IMO.

I know I may be splitting hairs. Any of the mentioned solutions are fine. But I am curious to see if something like this is not yet implemented in a more standard way. I was surprised to see that ``gethostbyname`` does not take an optional parameter for this task.

[toc] | [prev] | [next] | [standalone]


#55070

FromChris Angelico <rosuav@gmail.com>
Date2013-09-30 22:56 +1000
Message-ID<mailman.483.1380545808.18130.python-list@python.org>
In reply to#55067
On Mon, Sep 30, 2013 at 10:45 PM, Michel Albert <exhuma@gmail.com> wrote:
> I know I may be splitting hairs. Any of the mentioned solutions are fine. But I am curious to see if something like this is not yet implemented in a more standard way. I was surprised to see that ``gethostbyname`` does not take an optional parameter for this task.

gethostbyname is a simple function with not much flexibility. (You
can't, for instance, look up a TXT record.) For anything more complex,
you want a proper DNS implementation.

There are a few Python DNS modules. It means adding another
dependency, but perhaps not as large as twisted. And of course, you
could always manually send UDP packets and listen for responses, but
that seems a little unnecessary :)

ChrisA

[toc] | [prev] | [next] | [standalone]


#55074

From"Gisle Vanem" <gvanem@yahoo.no>
Date2013-09-30 15:35 +0200
Message-ID<mailman.486.1380548298.18130.python-list@python.org>
In reply to#55067
"Chris Angelico" <rosuav@gmail.com> wrote:

> There are a few Python DNS modules. It means adding another
> dependency, but perhaps not as large as twisted. And of course, you
> could always manually send UDP packets and listen for responses, but
> that seems a little unnecessary :)

Then there is pycares; "a Python module which provides an interface to 
c-ares.... c-ares is a C library that performs DNS requests and name resolves 
asynchronously.". I have good experience wih C-ares and it can set
specific nameservers. Ref:
  https://pypi.python.org/pypi/pycares/0.3.0

--gv

[toc] | [prev] | [next] | [standalone]


#55068

FromErvin Hegedüs <airween@gmail.com>
Date2013-09-30 14:54 +0200
Message-ID<mailman.482.1380545720.18130.python-list@python.org>
In reply to#55062
Hello,

On Mon, Sep 30, 2013 at 04:42:29AM -0700, Michel Albert wrote:
> Hi,
> 
> ``socket.gethostbyname`` sends the DNS resolution query to the DNS server specified by the OS. Is there an easy way to send a query to a *different* server?
> 
> I see that twisted.names allows you to do this, but, having all of twisted as dependency to my project when all I need to do is a simple DNS query seems a bit extreme. I also found pydns, but that looks fairly outdated and unmaintained.
> 
> Is there not an actively maintained lightweight solution? If not, I will go with twisted.
> 

there is a dns modul for Python (I don't know is it part of
standard Python library or not), on most Linux distribution you
can find it, eg. in Debian it's called python-dnspython.

It can handle different nameserver, than OS knows - here is a
sample code:


import dns.resolver

r = dns.resolver.Resolver()
r.namerservers =  ['127.0.0.1']
# or any other IP, in my case I'm using PDNS, which have two
# parts: a recursor and a resolver; recursor allows requests only
# on localhost

mxservers = r.query("python.org", 'MX').response




hth,


a.

 

[toc] | [prev] | [next] | [standalone]


#55072

FromMichel Albert <exhuma@gmail.com>
Date2013-09-30 06:04 -0700
Message-ID<b925ce7b-2c42-40a3-bfee-3368c8b0fed2@googlegroups.com>
In reply to#55068
On Monday, 30 September 2013 14:54:41 UTC+2, Ervin Hegedüs  wrote:
> Hello,
> 
> 
> 
> On Mon, Sep 30, 2013 at 04:42:29AM -0700, Michel Albert wrote:
> 
> > Hi,
> 
> > 
> 
> > ``socket.gethostbyname`` sends the DNS resolution query to the DNS server specified by the OS. Is there an easy way to send a query to a *different* server?
> 
> > 
> 
> > I see that twisted.names allows you to do this, but, having all of twisted as dependency to my project when all I need to do is a simple DNS query seems a bit extreme. I also found pydns, but that looks fairly outdated and unmaintained.
> 
> > 
> 
> > Is there not an actively maintained lightweight solution? If not, I will go with twisted.
> 
> > 
> 
> 
> 
> there is a dns modul for Python (I don't know is it part of
> 
> standard Python library or not), on most Linux distribution you
> 
> can find it, eg. in Debian it's called python-dnspython.
> 
> 
> 
> It can handle different nameserver, than OS knows - here is a
> 
> sample code:
> 
> 
> 
> 
> 
> import dns.resolver
> 
> 
> 
> r = dns.resolver.Resolver()
> 
> r.namerservers =  ['127.0.0.1']
> 
> # or any other IP, in my case I'm using PDNS, which have two
> 
> # parts: a recursor and a resolver; recursor allows requests only
> 
> # on localhost
> 
> 
> 
> mxservers = r.query("python.org", 'MX').response
> 
> 
> 
> 
> 
> 
> 
> 
> 
> hth,
> 
> 
> 
> 
> 
> a.


Indeed, this looks much nicer than both twisted or pydns. I think I'll go with that one. Thanks a lot!

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web