junjie 通过本文主要向大家介绍了python获取本机ip,python 本机ip,python获取linuxip,linux查看本机ip,linux查看本机ip地址等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
有时候使用到获取本机IP,就采用以下方式进行。
#!/usr/bin/python
import socket
import struct
import fcntl
def getip(ethname):
s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0X8915, struct.pack(‘256s', ethname[:15]))[20:24])
if __name__=='__main__':
print getip('eth0')
</div>

