ifconfig in python
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
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 : import socket as S
> In : s = S.socket(S.AF_INET, S.SOCK_DGRAM)
> In : s.connect(('192.0.2.1', 666))
> In : s.getsockname()
> Out: ('172.29.198.11', 46300)
> (No packets were sent during this process: UDP `connections' don't need
> explicit establishment. The network 192.0.2.0/24 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]
"lalalalala! it's not broken because I can use it"
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list