ifconfig in python

RasikaSrinivasan at gmail.com RasikaSrinivasan at gmail.com
Tue Jan 20 13:50:31 CET 2009

On Jan 20, 7:33 am, Mark Wooding <m... at distorted.org.uk> wrote:
> Дамјан Георгиевски <gdam... at gmail.com> writes:
> > Something *like*  this could work:
> >    myip = urllib2.urlopen('http://whatismyip.org/').read()
> This is going to cause all manner of problems.
> Firstly, many users are stuck behind NAT routers.  In this case, the
> external service will report the address of the router, which is
> probably useless -- certainly it will be for programs attempting to
> communicate over a LAN.
> Secondly, imagine the joy when overzealous ISPs decide that
> whatismyip.org is peddling kiddiepr0n (as happened to Wikipedia last
> month): then the service will report the address of ISP's censoring
> proxy to thousands of otherwise unrelated users.
> And that's before we get onto onion routers like Tor...
> Here's an idea which might do pretty well.
> In [1]: import socket as S
> In [2]: s = S.socket(S.AF_INET, S.SOCK_DGRAM)
> In [4]: s.connect(('', 666))
> In [5]: s.getsockname()
> Out[5]: ('', 46300)
> (No packets were sent during this process: UDP `connections' don't need
> explicit establishment.  The network is reserved for use in
> examples; selecting a local address should therefore exercise the
> default route almost everywhere.  If there's a specific peer address or
> network you want to communicate with, use that address explicitly.)
> I have to wonder what the purpose of this is.  It's much better to have
> the recipient of a packet work out the sender's address from the packet
> (using recvfrom or similar) because that actually copes with NAT and so
> on properly.
> -- [mdw]

one way to get your head around this is - IP Addresses are associated
with the interface and not the computer. distinction may be subtle but

More information about the Python-list mailing list