From 42d7135849a9069b2e04f3107ca2bda9b53d103a Mon Sep 17 00:00:00 2001 From: Papoteur Date: Sun, 31 May 2020 12:15:29 +0200 Subject: Add checking of present protocols, to avoid exception. --- src/monitor.py | 7 +++++++ src/net_monitor | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/monitor.py b/src/monitor.py index e7a3c12..3198b78 100644 --- a/src/monitor.py +++ b/src/monitor.py @@ -328,6 +328,13 @@ class Monitor: pass return routes, default_routes + def protocols_list(self): + protos = [] + for proto in ["tcp", "tcp6", "udp", "udp6"]: + if os.path.exists("/proc/net/%s" % proto): + protos.append(proto) + return protos + def get_connections(self, proto="tcp"): """Reads active connections""" connections=[] diff --git a/src/net_monitor b/src/net_monitor index cdd5c6d..4a8ddf9 100755 --- a/src/net_monitor +++ b/src/net_monitor @@ -559,7 +559,7 @@ class MonitorGui: """Updates connections""" lstore = self.connections lstore.clear() - for proto in ["tcp", "tcp6", "udp", "udp6"]: + for proto in self.monitor.protocols_list(): connections = self.monitor.get_connections(proto=proto) for loc_addr, loc_port, rem_addr, rem_port, status in connections: iter = lstore.append() -- cgit v1.2.1