如何根据网卡名获取到IP
import socket,struct,fcntldef get_ip(ifname):s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', bytes(ifname[:15],'utf-8')))[20:24])print("server ip:",get_ip('eth0'))