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. Advertisements

  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. Advertisements

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:
    539
    Craig G
    Mar 7, 2005
  2. Bernhard Schmidt

    result sorting in socket.getaddrinfo?

    Bernhard Schmidt, Oct 9, 2004, in forum: Python
    Replies:
    0
    Views:
    533
    Bernhard Schmidt
    Oct 9, 2004
  3. Replies:
    1
    Views:
    518
    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,713
    Chris Mellon
    Apr 10, 2007
  5. John Nagle
    Replies:
    2
    Views:
    577
    John Nagle
    Apr 21, 2007
  6. Laszlo Nagy
    Replies:
    1
    Views:
    7,238
    Mark Wooding
    Jan 27, 2009
  7. Steve Holden
    Replies:
    1
    Views:
    1,005
  8. Ruby Nuby
    Replies:
    2
    Views:
    518
    Ruby Nuby
    Sep 22, 2009
Loading...