gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow)
Chris Angelico
rosuav at gmail.com
Sun Sep 1 17:03:56 EDT 2013
On Mon, Sep 2, 2013 at 6:37 AM, <anntzer.lee at gmail.com> wrote:
> 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.
Perfect!
ChrisA
More information about the Python-list
mailing list