Skip to content

Commit

Permalink
ipv4 & ipv6
Browse files Browse the repository at this point in the history
  • Loading branch information
macos committed Jun 17, 2020
1 parent da968a7 commit 6483683
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
12 changes: 3 additions & 9 deletions clients/client-linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ def ip_status():
ip_check = 0
for i in [CU, CT, CM]:
try:
s = socket.create_connection((i, PORBEPORT), timeout=1)
s.close()
del s
socket.create_connection((i, PORBEPORT), timeout=1).close()
except:
ip_check += 1
if ip_check >= 2:
Expand All @@ -132,8 +130,7 @@ def get_network(ip_version):
elif(ip_version == 6):
HOST = "ipv6.google.com"
try:
s = socket.create_connection((HOST, 80), 2)
s.close()
socket.create_connection((HOST, 80), 2).close()
return True
except:
return False
Expand Down Expand Up @@ -163,17 +160,14 @@ def _ping_thread(host, mark, port):
startTime = time.time()

while True:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1)
try:
b = timeit.default_timer()
s.connect((host, port))
socket.create_connection((host, port), timeout=1).close()
pingTime[mark] = int((timeit.default_timer()-b)*1000)
except:
lostPacket += 1
finally:
allPacket += 1
s.close()

if allPacket > 100:
lostRate[mark] = float(lostPacket) / allPacket
Expand Down
12 changes: 3 additions & 9 deletions clients/client-psutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ def ip_status():
ip_check = 0
for i in [CU, CT, CM]:
try:
s = socket.create_connection((i, PORBEPORT), timeout=1)
s.close()
del s
socket.create_connection((i, PORBEPORT), timeout=1).close()
except:
ip_check += 1
if ip_check >= 2:
Expand All @@ -116,8 +114,7 @@ def get_network(ip_version):
elif(ip_version == 6):
HOST = "ipv6.google.com"
try:
s = socket.create_connection((HOST, 80), 2)
s.close()
socket.create_connection((HOST, 80), 2).close()
return True
except:
return False
Expand Down Expand Up @@ -147,17 +144,14 @@ def _ping_thread(host, mark, port):
startTime = time.time()

while True:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1)
try:
b = timeit.default_timer()
s.connect((host, port))
socket.create_connection((host, port), timeout=1).close()
pingTime[mark] = int((timeit.default_timer() - b) * 1000)
except:
lostPacket += 1
finally:
allPacket += 1
s.close()

if allPacket > 100:
lostRate[mark] = float(lostPacket) / allPacket
Expand Down

0 comments on commit 6483683

Please sign in to comment.