python获取本机网卡IP

def getLocalIp(ifname = 'eth0'):
	import socket, fcntl, struct;
	s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM);
	inet = fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', ifname[:15]));
	ip = socket.inet_ntoa(inet[20:24]);
	return ip;

你可能感兴趣的:(python,ifconfig)