Order of addresses returned by socket.gethostbyname_ex()

Tomas Lidén tomas.liden.privat at gmail.com
Mon Aug 22 11:06:30 CEST 2011

On 22 Aug, 10:15, Steven D'Aprano <steve
+comp.lang.pyt... at pearwood.info> wrote:
> On Mon, 22 Aug 2011 04:37 pm Tomas Lidén wrote:
> > In what order are the addresses returned by socket.gethostbyname_ex()?
> > We know that gethostbyname() is indeterministic but hope that
> > gethostbyname_ex() has a specified order.
> Did you want a particular order, or just any deterministic order?
> Have you considered sorting the addresses yourself?
> --
> Steven

In this particular case we have a host with several connections (LAN,
WIFI, VmWare adapters etc). When using gethostbyname() we got a VmWare
adapter but we wanted to get the LAN (or the "best" connection to our
server). With gethostbyname_ex() the ordering seemed to become LAN,
Wifi, etc and that's good for us. But we don't know if this holds on
other platforms (we're running on Windows 7).

A cross-platform deterministic order would be excellent for us.


More information about the Python-list mailing list