determine IP

Ed Leafe ed at leafe.com
Sun Nov 7 17:58:21 CET 2004


On Nov 7, 2004, at 11:53 AM, exarkun at divmod.com wrote:

>   The above code will _always_ return the local IP address, regardless 
> of NAT configuration.  For example, running on my desktop:
>
>>>> import socket
>>>> s = socket.socket()
>>>> s.connect(('google.com', 80))
>>>> print s.getsockname()
>     ('192.168.42.4', 40044)
>>>>
>>>>

	Not OMM:

 >>> import socket
 >>> s = socket.socket()
 >>> s.connect(('google.com', 80))
 >>> s.getsockname()
('66.66.222.137', 55096)
 >>>

	The local IP address is in the 192.168 subnet.

      ___/
     /
    __/
   /
  ____/
  Ed Leafe
  http://leafe.com/
  http://dabodev.com/




More information about the Python-list mailing list