diff --git a/clients/client-linux.py b/clients/client-linux.py index 23c6b15..88909f9 100755 --- a/clients/client-linux.py +++ b/clients/client-linux.py @@ -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: @@ -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 @@ -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 diff --git a/clients/client-psutil.py b/clients/client-psutil.py index 8dcfd46..bffa407 100755 --- a/clients/client-psutil.py +++ b/clients/client-psutil.py @@ -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: @@ -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 @@ -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