diff --git a/pupy/modules/ip.py b/pupy/modules/ip.py index 72f87eb7..d9b64606 100644 --- a/pupy/modules/ip.py +++ b/pupy/modules/ip.py @@ -23,16 +23,12 @@ class IPModule(PupyModule): def run(self, args): try: - data = obtain(self.client.conn.modules.pupyps.interfaces()) + rpupyps = self.client.conn.modules.pupyps + data = obtain(rpupyps.interfaces()) + families = { int(x):y for x,y in obtain(rpupyps.families).iteritems() } addrlen = max([len(x) for x in data['addrs']])+1 - families = { - v:k[3:] for k,v in socket.__dict__.iteritems() if k.startswith('AF_') - } - - families.update({-1: 'LINK'}) - familylen = max([len(v)-3 for v in families.itervalues()])+1 for addr, addresses in data['addrs'].iteritems(): diff --git a/pupy/modules/netstat.py b/pupy/modules/netstat.py index dd69ef3f..40d2b5a6 100644 --- a/pupy/modules/netstat.py +++ b/pupy/modules/netstat.py @@ -29,15 +29,10 @@ class NetStatModule(PupyModule): def run(self, args): try: - data = obtain(self.client.conn.modules.pupyps.connections()) - - families = { - v:k for k,v in socket.__dict__.iteritems() if k.startswith('AF_') - } - - sock = { - v:k for k,v in socket.__dict__.iteritems() if k.startswith('SOCK_') - } + rpupyps = self.client.conn.modules.pupyps + data = obtain(rpupyps.connections()) + sock = { int(x):y for x,y in obtain(rpupyps.socktypes).iteritems() } + families = { int(x):y for x,y in obtain(rpupyps.families).iteritems() } limit = [] @@ -55,8 +50,8 @@ class NetStatModule(PupyModule): continue color = "" - family = families[connection['family']][3:] - stype = sock[connection['type']][5:] + family = families[connection['family']] + stype = sock[connection['type']] if limit and not stype in limit: continue diff --git a/pupy/packages/all/pupyps.py b/pupy/packages/all/pupyps.py index 581ae5cc..f669dd90 100644 --- a/pupy/packages/all/pupyps.py +++ b/pupy/packages/all/pupyps.py @@ -6,6 +6,17 @@ import collections import sys import os import time +import socket + +families = { + v:k[3:] for k,v in socket.__dict__.iteritems() if k.startswith('AF_') +} +families.update({-1: 'LINK'}) + +socktypes = { + v:k[5:] for k,v in socket.__dict__.iteritems() if k.startswith('SOCK_') +} + def pstree(): data = {}