def get_ip_address(ifname):
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 35093, struct.pack('256s',
    ifname[:15]))[20:24])
get_ip_address('eth0')
How can I get the IP address of eth0 in Python?