gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow)

anntzer.lee at gmail.com anntzer.lee at gmail.com
Sun Sep 1 16:37:38 EDT 2013


On Sunday, September 1, 2013 4:37:34 AM UTC-7, Chris Angelico wrote:

> Yes, it most definitely CAN be a network config issue. The C function
> you want to be calling is getifaddrs(), and I don't think there's a
> way to call that from core Python. But a Google search for 'python
> getifaddrs' shows up a few third-party modules that might be of use to
> you; that'd be a lot quicker and more reliable than trying to look up
> your own hostname and depending on the results.
> 
> ChrisA

I tried using netifaces (https://pypi.python.org/pypi/netifaces) which seems to rely on getifaddrs (according to the doc, I didn't check the source).  Again, it returns nearly instantaneously the correct IP address.



More information about the Python-list mailing list