From d3c8df573bb3d2358aab3184d31869ac20a2589a Mon Sep 17 00:00:00 2001 From: Oleksii Shevchuk Date: Thu, 16 Mar 2017 21:45:08 +0200 Subject: [PATCH] Highlight own connection --- pupy/modules/netstat.py | 4 +++- pupy/packages/all/pupyps.py | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pupy/modules/netstat.py b/pupy/modules/netstat.py index 61d2e64e..dd69ef3f 100644 --- a/pupy/modules/netstat.py +++ b/pupy/modules/netstat.py @@ -61,7 +61,9 @@ class NetStatModule(PupyModule): if limit and not stype in limit: continue - if connection['status'] in ('CLOSE_WAIT', 'TIME_WAIT', 'TIME_WAIT2'): + if connection.get('me'): + color = 'green' + elif connection['status'] in ('CLOSE_WAIT', 'TIME_WAIT', 'TIME_WAIT2'): color = 'darkgrey' elif ( '127.0.0.1' in connection['laddr'] or '::1' in connection['laddr'] ): color = 'grey' diff --git a/pupy/packages/all/pupyps.py b/pupy/packages/all/pupyps.py index 5b4906d1..4a225327 100644 --- a/pupy/packages/all/pupyps.py +++ b/pupy/packages/all/pupyps.py @@ -100,6 +100,8 @@ def users(): def connections(): connections = [] + me = psutil.Process() + for connection in psutil.net_connections(): obj = { k:v for k,v in connection.__dict__.iteritems() } if connection.pid: @@ -108,6 +110,11 @@ def connections(): 'pid', 'exe', 'name', 'username' }) ) + if connection.pid == me.pid: + obj.update({ + 'me': True + }) + connections.append(obj) return connections