fix(Common):修正"testClentIP"变量获取
This commit is contained in:
@@ -6,11 +6,21 @@ 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()
|
||||
def get_host_IP(self, flag="50"):
|
||||
#try:
|
||||
#s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
#s.connect(('8.8.8.8', 80))
|
||||
#ip = s.getsockname()[0]
|
||||
#finally:
|
||||
#s.close()
|
||||
hostname = socket.gethostname()
|
||||
ipTriple = socket.gethostbyname_ex(hostname)
|
||||
ips = list(ipTriple[2:])
|
||||
ip = ""
|
||||
for i in ips:
|
||||
ipList = list(i)
|
||||
for ip1 in ipList:
|
||||
if "."+flag+"." in ip1:
|
||||
ip = ip1
|
||||
break
|
||||
return ip
|
||||
Reference in New Issue
Block a user