How to get IP address
Wayne Pierce
wayne at mishre.com
Sat Mar 1 14:33:27 EST 2003
Nagy László Zsolt <nagylzs at freemail.hu> wrote in message news:<mailman.1046487302.8558.python-list at python.org>...
> I'm trying to get all inet addresses of a machine in python. Is there a
> way to do it using
> the standard library? I found a solution on Google and in Python
> CookBook but they
> are platform dependent. I need a platform-independent solution. Thank
> you in advance.
>
> Laci 1.0
How about this? I only have one IP on my box so I do not know if this
will work for you..
socket.gethostbyaddr(socket.gethostname())
You could probably use the loopback as the parameter, like:
socket.gethostbyaddr('localhost')
Both of these will return a tuple in the form of (hostname, aliaslist,
ipaddrlist). This is in 7.2 of the Python docs if you need to check
other variations.
-W
More information about the Python-list
mailing list