ifconfig in python

Nehemiah Dacres vivacarlie at gmail.com
Tue Jan 20 18:48:09 CET 2009

I'll let this thought fester but I thought I'd put together a PEP to make
this a function. Possibly in some util library but preferibly in the sys
library sense this is where to get information about the system you are
running on.

On Tue, Jan 20, 2009 at 6:33 AM, Mark Wooding <mdw at distorted.org.uk> wrote:

> Дамјан Георгиевски <gdamjan at gmail.com> writes:
> > Something *like*  this could work:
> >
> >       myip = urllib2.urlopen('http://whatismyip.org/').read(<http://whatismyip.org/%27%29.read%28>
> )
> 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]
> --
> http://mail.python.org/mailman/listinfo/python-list


"lalalalala! it's not broken because I can use it"

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090120/598880af/attachment.html>

More information about the Python-list mailing list