Order of addresses returned by socket.gethostbyname_ex()

Tomas Lidén tomas.liden.privat at gmail.com
Mon Aug 22 07:29:38 EDT 2011


On 22 Aug, 12:06, Cameron Simpson <c... at zip.com.au> wrote:
>
> It would not surprise me if the order was related to the order a scan of
> the system interfaces yields information, and I would imagine that may
> be influenced by the order in which the interfaces were initialised.
>
> So getting the LAN first may merely be fortuitous.
> I wouldn't rely on it, especially if interfaces come and go.
>

We did try to disable/enable the interfaces in different orders, but
always got the same return order from gethostbyname_ex(). So it looked
pretty stable (on that specific OS). There's been some testing on
Linux as well, but since this should be used in a general cross
platform tool we wanted to check the exact behaviour of the method.

> What if you queried your routing table instead? Usually there's just one
> default route, and hopefully it would be configured to use the "best"
> interface.
>

Hmm... perhaps. How would you do that?
/Tomas



More information about the Python-list mailing list