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.'    

 

posted @ 2014-06-20 13:58  neuhxy  阅读(368)  评论(0编辑  收藏  举报