首页 > 代码库 > Python 获取本机IP地址

Python 获取本机IP地址

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.