aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugeni Dodonov <eugeni@mandriva.com>2010-06-05 18:23:35 -0300
committerEugeni Dodonov <eugeni@mandriva.com>2010-06-05 18:23:35 -0300
commit5494b15d444bf7c43f01a96ca5fa80c0c8aa4c0e (patch)
tree269dda20cb31ec6b59e054dcb7cc5b31db658498
parent7e7e40905b0a894f88d165781f631459886fd488 (diff)
downloadnet_monitor-5494b15d444bf7c43f01a96ca5fa80c0c8aa4c0e.tar
net_monitor-5494b15d444bf7c43f01a96ca5fa80c0c8aa4c0e.tar.gz
net_monitor-5494b15d444bf7c43f01a96ca5fa80c0c8aa4c0e.tar.bz2
net_monitor-5494b15d444bf7c43f01a96ca5fa80c0c8aa4c0e.tar.xz
net_monitor-5494b15d444bf7c43f01a96ca5fa80c0c8aa4c0e.zip
parse connection statuses
-rw-r--r--src/monitor.py43
1 files changed, 42 insertions, 1 deletions
diff --git a/src/monitor.py b/src/monitor.py
index 88e16ff..893cd10 100644
--- a/src/monitor.py
+++ b/src/monitor.py
@@ -27,6 +27,37 @@ class Monitor:
# wireless modes
modes = ['Auto', 'Ad-Hoc', 'Managed', 'Master', 'Repeat', 'Second', 'Monitor']
+ # tcp statuses
+ netstats = {"tcp": [
+ "",
+ _("ESTABLISHED"),
+ _("SYN_SENT"),
+ _("SYN_RECV"),
+ _("FIN_WAIT1"),
+ _("FIN_WAIT2"),
+ _("TIME_WAIT"),
+ _("CLOSE"),
+ _("CLOSE_WAIT"),
+ _("LAST_ACK"),
+ _("LISTEN"),
+ _("CLOSING")
+ ],
+ "udp": [
+ "",
+ _("ESTABLISHED"),
+ _("SYN_SENT"),
+ _("SYN_RECV"),
+ _("FIN_WAIT1"),
+ _("FIN_WAIT2"),
+ _("TIME_WAIT"),
+ "",
+ _("CLOSE_WAIT"),
+ _("LAST_ACK"),
+ _("LISTEN"),
+ _("CLOSING")
+ ],
+ }
+
# constants
SIZE_KB=1000
SIZE_MB=1000**2
@@ -259,6 +290,10 @@ class Monitor:
traceback.print_exc()
return connections
+ if proto in self.netstats:
+ netstats = self.netstats[proto]
+ else:
+ netstats = None
# parse connections
for l in data:
fields = l.strip().split()
@@ -271,7 +306,13 @@ class Monitor:
loc_port = (int(loc_p, 16))
rem_addr = socket.inet_ntoa(struct.pack('i', int(rem_a, 16)))
rem_port = (int(rem_p, 16))
- connections.append((loc_addr, loc_port, rem_addr, rem_port, status))
+ # parse status
+ status = int(status, 16)
+ status_s = _("Unknown")
+ if netstats:
+ if status < len(netstats):
+ status_s = netstats[status]
+ connections.append((loc_addr, loc_port, rem_addr, rem_port, status_s))
return connections
def load_uptime_log(self):