1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-15 01:24:29 +02:00

netstat debugging

This commit is contained in:
Kelly Brazil
2019-10-17 10:54:37 -07:00
parent 7071f60a30
commit a5e039d4c2

View File

@ -35,7 +35,8 @@ def parse_line(entry):
output_line['local'] = parsed_line[3] output_line['local'] = parsed_line[3]
output_line['foreign'] = parsed_line[4] output_line['foreign'] = parsed_line[4]
# output_line['state'] = parsed_line[6] if len(parsed_line) > 5:
output_line['state'] = parsed_line[5]
output_line['recvq'] = int(parsed_line[1]) output_line['recvq'] = int(parsed_line[1])
output_line['sendq'] = int(parsed_line[2]) output_line['sendq'] = int(parsed_line[2])
# output_line['pid'] = int(parsed_line[1]) # output_line['pid'] = int(parsed_line[1])
@ -47,6 +48,7 @@ def parse(data):
cleandata = data.splitlines() cleandata = data.splitlines()
for line in cleandata: for line in cleandata:
if line.find('Active Internet connections (w/o servers)') == 0: if line.find('Active Internet connections (w/o servers)') == 0:
state.section = "client" state.section = "client"
continue continue
@ -61,7 +63,20 @@ def parse(data):
if line.find('Active UNIX') == 0: if line.find('Active UNIX') == 0:
break break
if state.section == "client": if state.section == 'client':
if line.find('tcp') == 0:
state.session = 'tcp'
if line.find('p6') == 2:
state.network = 'ipv6'
else:
state.network = 'ipv4'
elif line.find('udp') == 0:
state.session = 'udp'
if line.find('p6') == 2:
state.network = 'ipv6'
else:
state.network = 'ipv4'
elif state.section == 'server':
if line.find('tcp') == 0: if line.find('tcp') == 0:
state.session = 'tcp' state.session = 'tcp'
if line.find('p6') == 2: if line.find('p6') == 2:
@ -75,19 +90,11 @@ def parse(data):
else: else:
state.network = 'ipv4' state.network = 'ipv4'
if state.section == "server": print(line)
if line.find('tcp') == 0: print(f'section: {state.section}')
state.session = 'tcp' print(f'session: {state.session}')
if line.find('p6') == 2: print(f'network: {state.network}')
state.network = 'ipv6' print()
else:
state.network = 'ipv4'
elif line.find('udp') == 0:
state.session = 'udp'
if line.find('p6') == 2:
state.network = 'ipv6'
else:
state.network = 'ipv4'
if state.section == 'client' and state.session == 'tcp' and state.network == 'ipv4': if state.section == 'client' and state.session == 'tcp' and state.network == 'ipv4':
state.client_tcp_ip4.append(parse_line(line)) state.client_tcp_ip4.append(parse_line(line))
@ -105,15 +112,18 @@ def parse(data):
if state.section == 'server' and state.session == 'tcp' and state.network == 'ipv4': if state.section == 'server' and state.session == 'tcp' and state.network == 'ipv4':
state.server_tcp_ip4.append(parse_line(line)) state.server_tcp_ip4.append(parse_line(line))
if state.section == 'client' and state.session == 'tcp' and state.network == 'ipv6': if state.section == 'server' and state.session == 'tcp' and state.network == 'ipv6':
state.server_tcp_ip6.append(parse_line(line)) state.server_tcp_ip6.append(parse_line(line))
if state.section == 'client' and state.session == 'udp' and state.network == 'ipv4': if state.section == 'server' and state.session == 'udp' and state.network == 'ipv4':
state.server_udp_ip4.append(parse_line(line)) state.server_udp_ip4.append(parse_line(line))
if state.section == 'client' and state.session == 'udp' and state.network == 'ipv6': if state.section == 'server' and state.session == 'udp' and state.network == 'ipv6':
state.server_udp_ip6.append(parse_line(line)) state.server_udp_ip6.append(parse_line(line))
state.session = ''
state.network = ''
# build dictionary # build dictionary
if state.client_tcp_ip4: if state.client_tcp_ip4:
if 'client' not in output: if 'client' not in output: