Re: making socket.getaddrinfo use cached dns

Discussion in 'Python' started by Chris Angelico, Jul 7, 2011.

  1. On Fri, Jul 8, 2011 at 4:18 AM, high bandwidth <> wrote:
    > I use cached dns lookups with pdnsd on my ubuntu machine to speed up web
    > access as regular lookups can take 15-30 seconds. However, python's
    > mechanize and urllib etc use socket.getaddrinfo, which seems not to be using
    > dns cacheing or taking a long time because of ipv6 lookups. In either case,
    > I subsequent access to the same site to be fast and not require lengthy
    > calls to getaddrinfo. How can I get python to correctly use cached dns
    > lookups and ipv4 only (at least in those cases where it is appropriate).


    One solution would be to do your own DNS lookups and then pass urllib
    an IP address. Is pdnsd set up to be your computer's primary resolver?
    (Is /etc/resolv.conf pointing to localhost?) If not, that might help.
    I've generally done my DNS caching using BIND, so I can't help with
    pdnsd specifically.

    ChrisA
     
    Chris Angelico, Jul 7, 2011
    #1
    1. Advertising

  2. Chris Angelico

    Nobody Guest

    On Fri, Jul 8, 2011 at 4:18 AM, high bandwidth <> wrote:

    >> I use cached dns lookups with pdnsd on my ubuntu machine to speed up
    >> web access as regular lookups can take 15-30 seconds. However, python's
    >> mechanize and urllib etc use socket.getaddrinfo, which seems not to be
    >> using dns cacheing or taking a long time because of ipv6 lookups. In
    >> either case, I subsequent access to the same site to be fast and not
    >> require lengthy calls to getaddrinfo. How can I get python to correctly
    >> use cached dns lookups and ipv4 only (at least in those cases where it
    >> is appropriate).


    To only query IPv4 addresses, pass socket.AF_INET as the third argument
    (family) to socket.getaddrinfo(). The default is AF_UNSPEC (= 0), which
    will return both IPv4 and IPv6 addresses.
     
    Nobody, Jul 8, 2011
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Craig G
    Replies:
    0
    Views:
    393
    Craig G
    Mar 7, 2005
  2. Bernhard Schmidt

    result sorting in socket.getaddrinfo?

    Bernhard Schmidt, Oct 9, 2004, in forum: Python
    Replies:
    0
    Views:
    370
    Bernhard Schmidt
    Oct 9, 2004
  3. Replies:
    1
    Views:
    365
    Gabriel Genellina
    Dec 23, 2006
  4. Thomas Dybdahl Ahle

    Kill thread or at least socket.getaddrinfo

    Thomas Dybdahl Ahle, Mar 26, 2007, in forum: Python
    Replies:
    3
    Views:
    1,512
    Chris Mellon
    Apr 10, 2007
  5. Ruby Nuby
    Replies:
    2
    Views:
    380
    Ruby Nuby
    Sep 22, 2009
Loading...

Share This Page