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. <br><br><div class="gmail_quote">On Tue, Jan 20, 2009 at 6:33 AM, Mark Wooding <span dir="ltr"><<a href="mailto:mdw@distorted.org.uk">mdw@distorted.org.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">Дамјан Георгиевски <<a href="mailto:gdamjan@gmail.com">gdamjan@gmail.com</a>> writes:<br>
<br>
> Something *like*  this could work:<br>
><br>
>       myip = urllib2.urlopen('<a href="http://whatismyip.org/%27%29.read%28" target="_blank">http://whatismyip.org/').read(</a>)<br>
<br>
</div>This is going to cause all manner of problems.<br>
<br>
Firstly, many users are stuck behind NAT routers.  In this case, the<br>
external service will report the address of the router, which is<br>
probably useless -- certainly it will be for programs attempting to<br>
communicate over a LAN.<br>
<br>
Secondly, imagine the joy when overzealous ISPs decide that<br>
<a href="http://whatismyip.org" target="_blank">whatismyip.org</a> is peddling kiddiepr0n (as happened to Wikipedia last<br>
month): then the service will report the address of ISP's censoring<br>
proxy to thousands of otherwise unrelated users.<br>
<br>
And that's before we get onto onion routers like Tor...<br>
<br>
Here's an idea which might do pretty well.<br>
<br>
In [1]: import socket as S<br>
In [2]: s = S.socket(S.AF_INET, S.SOCK_DGRAM)<br>
In [4]: s.connect(('192.0.2.1', 666))<br>
In [5]: s.getsockname()<br>
Out[5]: ('172.29.198.11', 46300)<br>
<br>
(No packets were sent during this process: UDP `connections' don't need<br>
explicit establishment.  The network <a href="http://192.0.2.0/24" target="_blank">192.0.2.0/24</a> is reserved for use in<br>
examples; selecting a local address should therefore exercise the<br>
default route almost everywhere.  If there's a specific peer address or<br>
network you want to communicate with, use that address explicitly.)<br>
<br>
I have to wonder what the purpose of this is.  It's much better to have<br>
the recipient of a packet work out the sender's address from the packet<br>
(using recvfrom or similar) because that actually copes with NAT and so<br>
on properly.<br>
<br>
-- [mdw]<br>
<div><div></div><div class="Wj3C7c">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><br>"lalalalala! it's not broken because I can use it"<br><br><a href="http://linux.slashdot.org/comments.pl?sid=194281&threshold=1&commentsort=0&mode=thread&cid=15927703">http://linux.slashdot.org/comments.pl?sid=194281&threshold=1&commentsort=0&mode=thread&cid=15927703</a><br>