MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / netstat

Function netstat

test/functional/test_framework/netutil.py:55–74  ·  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

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

Callers 1

get_bind_addrsFunction · 0.85

Calls 2

_remove_emptyFunction · 0.85
_convert_ip_portFunction · 0.85

Tested by

no test coverage detected