From: vsr Date: Tue, 13 Oct 2020 16:42:20 +0000 (+0300) Subject: #20171 [CEA 20071] Handle missing netstat X-Git-Tag: V9_6_0b1^0 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7a8f377e812e9a06775c6bccbfbf5b241347e13e;p=modules%2Fkernel.git #20171 [CEA 20071] Handle missing netstat --- diff --git a/bin/PortManager.py b/bin/PortManager.py index 5371fcf21..aace9e17b 100644 --- a/bin/PortManager.py +++ b/bin/PortManager.py @@ -120,9 +120,23 @@ def __isNetworkConnectionActiveOnPort(port): except: print("Error when trying to access active network connections.") if err: print(err) - import traceback - traceback.print_exc() - return False + print("... Presumably this package is not installed...Please install netstat if available for your distribution.") + print("... Trying socket based approach") + try: + import socket + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + result = sock.connect_ex(("127.0.0.1", port)) + if result == 0: + print("Port %r: Closed" % (port)) + sock.close() + return True + else: + sock.close() + return False + except: + import traceback + traceback.print_exc() + return False from io import StringIO buf = StringIO(out.decode('utf-8', 'ignore'))