16 lines
298 B
Python
16 lines
298 B
Python
|
|
#coding=utf-8
|
||
|
|
import socket
|
||
|
|
|
||
|
|
""" 获取主机信息 """
|
||
|
|
class mytool():
|
||
|
|
def __init__(self):
|
||
|
|
pass
|
||
|
|
|
||
|
|
def get_host_IP(self):
|
||
|
|
try:
|
||
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||
|
|
s.connect(('8.8.8.8', 80))
|
||
|
|
ip = s.getsockname()[0]
|
||
|
|
finally:
|
||
|
|
s.close()
|
||
|
|
return ip
|