import socket #获取本机IP地址 self.local_ip = socket.gethostbyname(socket.gethostname()) print (self.local_ip)
python 判断本机是否联网
1 timeout = 200 2 host = ‘www.baidu.com‘ 3 port = 80 4 s=socket.socket() 5 s.settimeout(timeout) 6 status = s.connect_ex((host,port)) 7 if status == 0: 8 #Connect OK 9 else: 10 print ‘ping error.‘
Python 获取本机IP地址,布布扣,bubuko.com
原文:http://www.cnblogs.com/purple-blog/p/3799208.html