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


Groups > comp.lang.python > #55068

Re: DNS query against a specific server.

Date 2013-09-30 14:54 +0200
From Ervin Hegedüs <airween@gmail.com>
Subject Re: DNS query against a specific server.
References <634fa158-1d15-4a7e-ac0f-7a3f57f55cc7@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.482.1380545720.18130.python-list@python.org> (permalink)

Show all headers | View raw


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.

 

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web