How to get all IP addresses in python?

Steve Pinard spinard at
Fri Jul 11 17:15:45 CEST 2003

Try socket.getaddrinfo rather than socket.gethostbyname.  It returns a
list of tuples.  tuple[4][0] of each list element is the IP address.

addrs = socket.getaddrinfo(socket.gethostname(), None)
for addr in addrs:
    print addr[4][0]

The above worked on my machine but I only have one NIC card.

- Steve

More information about the Python-list mailing list