MCPcopy Create free account
hub / github.com/ElementsProject/elements / netstat

Function netstat

test/functional/test_framework/netutil.py:54–73  ·  view source on GitHub ↗

Function to return a list with status of tcp connections at linux systems To get pid of all network process running on system, you must run this script as superuser

(typ='tcp')

Source from the content-addressed store, hash-verified

52 return host_out,int(port,16)
53
54def netstat(typ='tcp'):
55 '''
56 Function to return a list with status of tcp connections at linux systems
57 To get pid of all network process running on system, you must run this script
58 as superuser
59 '''
60 with open('/proc/net/'+typ,'r',encoding='utf8') as f:
61 content = f.readlines()
62 content.pop(0)
63 result = []
64 for line in content:
65 line_array = _remove_empty(line.split(' ')) # Split lines and remove empty spaces.
66 tcp_id = line_array[0]
67 l_addr = _convert_ip_port(line_array[1])
68 r_addr = _convert_ip_port(line_array[2])
69 state = line_array[3]
70 inode = int(line_array[9]) # Need the inode to match with process pid.
71 nline = [tcp_id, l_addr, r_addr, state, inode]
72 result.append(nline)
73 return result
74
75def get_bind_addrs(pid):
76 '''

Callers 1

get_bind_addrsFunction · 0.70

Calls 2

_remove_emptyFunction · 0.70
_convert_ip_portFunction · 0.70

Tested by

no test coverage detected