determine IP
Ed Leafe
ed at leafe.com
Sun Nov 7 11:38:57 EST 2004
On Nov 7, 2004, at 11:04 AM, exarkun at divmod.com wrote:
>> is there a cross platform way to determine a local machines IP on a
>> network (LAN or internet) in python?
>>
>
> s = socket.socket()
> s.connect(('google.com', 80))
> print s.getsockname()
If you are on a NAT machine on the local network, the above will
return the public IP of the network. If you change the target from
'google.com' to a machine on your subnet that will accept the
connection, you'll get the local IP address.
___/
/
__/
/
____/
Ed Leafe
http://leafe.com/
http://dabodev.com/
More information about the Python-list
mailing list