#!/usr/bin/python
# -*- coding: UTF-8 -*-
import socket, fcntl, struct
def get_local_ip(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
inet = fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', ifname[:15]))
ret = socket.inet_ntoa(inet[20:24])
return ret
print(get_local_ip("eth0"))
print(get_local_ip("lo"))