how to obtain its ip address ?

Lee Harr missive at frontiernet.net
Wed Jun 23 17:03:45 EDT 2004


On 2004-06-23, marco <manatlan at online.fr> wrote:
> I'd search a lot ... but i had not found
> how can i obtain my ip address (when i'm connected to the www) ?!
>


Probably it will depend somewhat on your operating system.
This works for me ...

>>> import socket
>>> socket.gethostbyname('localhost')
'127.0.0.1'
>>> hostname = socket.gethostname()
>>> hostname
'homer'
>>> socket.gethostbyname(hostname)
'172.16.0.5'




More information about the Python-list mailing list