2,获取本地IP地址与hostanme
1)、windows和linux下
 
import socket
localIP=socket.gethostbyname(socket.gethostname())
print "local ip:%s "%localIP
ipList=socket.gethostbyname_ex(socket.gethostname())
for i in ipList:
    if i!=localIP:
        print "external IP:%s"%i
 
2)、linux系统中
 
import socket,fcntl,struct
def get_ip_address(ifname):
        s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
        return socket.inet_ntoa(fcntl.ioctl(
                s.fileno(),
                0x8915,
                struct.pack('256s',ifname[:15])
        )[20:24])
print get_ip_address('eth0')