determine IP
Jan Dries
jan.dries at dcube-resource.be
Sun Nov 7 11:06:28 EST 2004
Keir Lawson wrote:
> is there a cross platform way to determine a local machines IP on a
> network (LAN or internet) in python?
In the past I've used the following code for that:
import socket
address = socket.gethostbyname(socket.gethostname())
It worked fine in my situation, but may not be what you are looking for.
For instance, if your host has multiple addresses, the above may not
return the one you want. In those cases, gethostbyname_ex() will return
a list of addresses.
Anyway, see the docs for more information.
Regards,
Jan
More information about the Python-list
mailing list