how to obtain its ip address ?

Daniel Yoo dyoo at
Wed Jun 23 22:42:26 CEST 2004

marco <manatlan at> 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) ?!

Hi Marco,

Here's a quicky way to do it:

import socket

def getSelfIp():
    """Returns the IP address of the local host."""
    return socket.gethostbyname(socket.gethostname())

This might not work perfectly.  If you want something more
comprehensive, you may want to use something like the localIP()
function in Webware:

This appears to be a bit more systematic in getting a good local IP

Good luck to you!

More information about the Python-list mailing list