[CentralOH] Local IP Address in Python

Mark Erbaugh mark at microenh.com
Wed May 18 18:12:40 CEST 2011

On May 18, 2011, at 8:08 AM, Mark Erbaugh wrote:

> Is there a Python library function to determine the IP address or addresses of the local machine?  I'm looking for something that provides the information similar to what is displayed when you run ifconfig (Posix) or ipconfig (Windows)?
> Thanks,
> Mark

I'll answer my own question for others who might be interested:

import socket

x = [i[4][0] for i in socket.getaddrinfo(socket.gethostname(), None, socket.AF_INET, socket.SOCK_STREAM)]

This seems to work on both my Mac and Windows.

More information about the CentralOH mailing list