How to get all IP addresses in python?

Yun Mao maoy_REMOVE_IF_NOT_SPAM at cis.upenn.edu
Fri Jul 11 06:54:47 CEST 2003


Hi. I did a little homework on google for this question. The answer was:
>>> import socket
>>> hostname = socket.gethostname()
>>> ip = socket.gethostbyname(hostname)
>>> print ip
192.168.55.101
But what if I have several interfaces, say eth0, eth0:1, eth1, etc. How to
get all of them? It would be a little undesirable if people suggest to parse
the result of ifconfig because I in particular want the code to be cross
platform. Thanks a lot!

Yun






More information about the Python-list mailing list