Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #12054

Re: Order of addresses returned by socket.gethostbyname_ex()

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <cameron@cskk.homeip.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'bsd': 0.05; 'think,': 0.05; 'received:edu.au': 0.07; '(possibly': 0.09; 'command.': 0.09; 'corresponds': 0.09; 'subject:()': 0.09; 'subject:addresses': 0.09; 'interfaces': 0.12; 'hopefully': 0.15; 'method.': 0.15; '"0.0.0.0")': 0.16; '-rn': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'iirc,': 0.16; 'lan': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'murray': 0.16; 'pulled': 0.16; 'received:202.125.174': 0.16; 'received:202.125.174.133': 0.16; 'received:boardofstudies.nsw.edu.au': 0.16; 'received:cskk.homeip.net': 0.16; 'received:harvey.boardofstudies.nsw.edu.au': 0.16; 'received:homeip.net': 0.16; 'received:nsw.edu.au': 0.16; 'systems)': 0.16; 'cc:addr:python-list': 0.16; 'looked': 0.16; 'wrote:': 0.16; "wouldn't": 0.17; 'linux': 0.17; 'cheers,': 0.18; 'australian': 0.18; 'that?': 0.18; 'to:2**1': 0.20; 'cc:no real name:2**0': 0.20; "doesn't": 0.22; 'cc:2**0': 0.22; 'header:In- Reply-To:1': 0.22; 'interface': 0.23; '(or': 0.23; '(on': 0.23; 'command': 0.24; 'testing': 0.24; 'stack': 0.24; 'windows': 0.26; '(this': 0.28; 'cc:addr:python.org': 0.30; 'influenced': 0.30; 'yields': 0.30; 'seem': 0.31; 'go.': 0.32; 'usually': 0.32; 'probably': 0.33; 'there': 0.33; 'operating': 0.33; 'header:User- Agent:1': 0.34; 'pretty': 0.35; 'to:no real name:2**1': 0.35; 'anything': 0.36; 'received:au': 0.36; 'interface.': 0.37; 'pull': 0.37; 'listed': 0.37; 'using': 0.37; 'run': 0.37; 'but': 0.37; 'especially': 0.37; 'configured': 0.38; 'cross': 0.38; 'stable': 0.38; 'some': 0.38; 'platform': 0.38; 'should': 0.38; 'subject:: ': 0.39; 'getting': 0.39; "there's": 0.39; "it's": 0.40; 'your': 0.61; 'order': 0.62; 'increase': 0.63; 'information,': 0.65; 'received:202': 0.66; 'cameron': 0.67; 'exact': 0.68; 'imagine': 0.71; 'price': 0.76; 'average': 0.77; 'subject:Order': 0.77; 'chapman': 0.84; 'hmm...': 0.84; 'shit': 0.84; 'subject:skip:s 20': 0.91; 'orders,': 0.95; 'surprise': 0.97
Date Tue, 23 Aug 2011 08:46:36 +1000
From Cameron Simpson <cs@zip.com.au>
To Tomas@cskk.homeip.net, Lid�n <tomas.liden.privat@gmail.com>@cskk.homeip.net
Subject Re: Order of addresses returned by socket.gethostbyname_ex()
MIME-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Disposition inline
Content-Transfer-Encoding 8bit
In-Reply-To <bed10d56-f5dc-4ffc-b42b-1eeec5d6c619@w11g2000vbp.googlegroups.com>
User-Agent Mutt/1.5.21 (2010-09-15)
References <bed10d56-f5dc-4ffc-b42b-1eeec5d6c619@w11g2000vbp.googlegroups.com>
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.331.1314053201.27778.python-list@python.org> (permalink)
Lines 44
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1314053201 news.xs4all.nl 23926 [2001:888:2000:d::a6]:46532
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:12054

Show key headers only | View raw


On 22Aug2011 04:29, Tomas Lid�n <tomas.liden.privat@gmail.com> wrote:
| On 22 Aug, 12:06, Cameron Simpson <c...@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?

On UNIX systems (and, I think, also Windows systems) you'd run the command:

  netstat -rn

or use the "route" command. (This avoids using operating system calls
directly - the command will know what to do itself.)

I seem to recall that Windows has the netstat command as well (possibly
because, IIRC, they pulled in the BSD UNIX IP stack for their first IP
implementation).

Anyway, by popening the netstat command you can pull the "default" (or
"0.0.0.0") route from its output. Then see if the interface listed there
corresponds to what you need to know.

Cheers,
-- 
Cameron Simpson <cs@zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

Then again, it's probably really because your average Australian doesn't give
a shit about anything that doesn't increase the price of beer.
        - Murray Chapman <muzzle@cs.uq.oz.au>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Order of addresses returned by socket.gethostbyname_ex() Tomas Lidén <tomas@liden-privat.net> - 2011-08-21 23:37 -0700
  Re: Order of addresses returned by socket.gethostbyname_ex() Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-22 18:15 +1000
    Re: Order of addresses returned by socket.gethostbyname_ex() Tomas Lidén <tomas.liden.privat@gmail.com> - 2011-08-22 02:06 -0700
      Re: Order of addresses returned by socket.gethostbyname_ex() Cameron Simpson <cs@zip.com.au> - 2011-08-22 20:06 +1000
        Re: Order of addresses returned by socket.gethostbyname_ex() Tomas Lidén <tomas.liden.privat@gmail.com> - 2011-08-22 04:29 -0700
          Re: Order of addresses returned by socket.gethostbyname_ex() Cameron Simpson <cs@zip.com.au> - 2011-08-23 08:46 +1000
      Re: Order of addresses returned by socket.gethostbyname_ex() Chris Angelico <rosuav@gmail.com> - 2011-08-22 11:36 +0100
        Re: Order of addresses returned by socket.gethostbyname_ex() Tomas Lidén <tomas.liden.privat@gmail.com> - 2011-08-22 04:32 -0700
      Re: Order of addresses returned by socket.gethostbyname_ex() Roy Smith <roy@panix.com> - 2011-08-22 07:37 -0400
        Re: Order of addresses returned by socket.gethostbyname_ex() Paul Kölle <paul@subsignal.org> - 2011-08-22 14:18 +0200
          Re: Order of addresses returned by socket.gethostbyname_ex() Tomas Lidén <tomas.liden.privat@gmail.com> - 2011-08-22 05:33 -0700
      Re: Order of addresses returned by socket.gethostbyname_ex() Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-23 02:09 +1000
  Re: Order of addresses returned by socket.gethostbyname_ex() Roy Smith <roy@panix.com> - 2011-08-22 07:26 -0400
    Re: Order of addresses returned by socket.gethostbyname_ex() Tomas Lidén <tomas.liden.privat@gmail.com> - 2011-08-22 04:39 -0700
      Re: Order of addresses returned by socket.gethostbyname_ex() Roy Smith <roy@panix.com> - 2011-08-22 08:14 -0400
      Re: Order of addresses returned by socket.gethostbyname_ex() Terry Reedy <tjreedy@udel.edu> - 2011-08-22 13:34 -0400
  Re: Order of addresses returned by socket.gethostbyname_ex() Nobody <nobody@nowhere.com> - 2011-08-22 20:12 +0100

csiph-web