Highlight own connection

This commit is contained in:
Oleksii Shevchuk 2017-03-16 21:45:08 +02:00
parent 8ff4031047
commit d3c8df573b
2 changed files with 10 additions and 1 deletions

View File

@ -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'

View File

@ -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