1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00

add netstat -r support for linux

This commit is contained in:
Kelly Brazil
2020-05-22 12:00:26 -07:00
parent 5d0dbece93
commit ec2cd2d708
9 changed files with 70 additions and 11 deletions

View File

@ -374,16 +374,19 @@ Returns:
"sndbuf": integer, "sndbuf": integer,
"rxbytes": integer, "rxbytes": integer,
"txbytes": integer, "txbytes": integer,
"destination": string, "destination": string,
"gateway": string, "gateway": string,
"route_flags": string, "route_flags": string,
"route_refs": integer, "route_refs": integer,
"use": integer, "use": integer,
"mtu": integer, "mtu": integer,
"netif": string, "expire": string,
"expire": string "genmask": string,
"mss": integer,
"window": integer,
"irtt": integer,
"iface": string,
"metric": integer
} }
] ]

View File

@ -381,16 +381,19 @@ def process(proc_data):
"sndbuf": integer, "sndbuf": integer,
"rxbytes": integer, "rxbytes": integer,
"txbytes": integer, "txbytes": integer,
"destination": string, "destination": string,
"gateway": string, "gateway": string,
"route_flags": string, "route_flags": string,
"route_refs": integer, "route_refs": integer,
"use": integer, "use": integer,
"mtu": integer, "mtu": integer,
"netif": string, "expire": string,
"expire": string "genmask": string,
"mss": integer,
"window": integer,
"irtt": integer,
"iface": string,
"metric": integer
} }
] ]
""" """
@ -398,7 +401,7 @@ def process(proc_data):
# integer changes # integer changes
int_list = ['recv_q', 'send_q', 'pid', 'refcnt', 'inode', 'unit', 'vendor', 'class', int_list = ['recv_q', 'send_q', 'pid', 'refcnt', 'inode', 'unit', 'vendor', 'class',
'osx_flags', 'subcla', 'pcbcount', 'rcvbuf', 'sndbuf', 'rxbytes', 'txbytes', 'osx_flags', 'subcla', 'pcbcount', 'rcvbuf', 'sndbuf', 'rxbytes', 'txbytes',
'route_refs', 'use', 'mtu'] 'route_refs', 'use', 'mtu', 'mss', 'window', 'irtt', 'metric']
for key in int_list: for key in int_list:
if key in entry: if key in entry:
try: try:

View File

@ -14,6 +14,15 @@ def normalize_headers(header):
return header return header
def normalize_route_headers(header):
header = header.lower()
header = header.replace('flags', 'route_flags')
header = header.replace('ref', 'route_refs')
header = header.replace('-', '_')
return header
def parse_network(headers, entry): def parse_network(headers, entry):
# Count words in header # Count words in header
# if len of line is one less than len of header, then insert None in field 5 # if len of line is one less than len of header, then insert None in field 5
@ -62,6 +71,14 @@ def parse_socket(header_text, headers, entry):
return output_line return output_line
def parse_route(headers, entry):
entry = entry.split(maxsplit=len(headers) - 1)
output_line = dict(zip(headers, entry))
output_line['kind'] = 'route'
return output_line
def parse_post(raw_data): def parse_post(raw_data):
# clean up trailing whitespace on each item in each entry # clean up trailing whitespace on each item in each entry
# flags --- = null # flags --- = null
@ -139,6 +156,7 @@ def parse(cleandata):
network = False network = False
socket = False socket = False
bluetooth = False bluetooth = False
routing_table = False
headers = None headers = None
for line in cleandata: for line in cleandata:
@ -147,18 +165,28 @@ def parse(cleandata):
network = True network = True
socket = False socket = False
bluetooth = False bluetooth = False
routing_table = False
continue continue
if line.startswith('Active UNIX'): if line.startswith('Active UNIX'):
network = False network = False
socket = True socket = True
bluetooth = False bluetooth = False
routing_table = False
continue continue
if line.startswith('Active Bluetooth'): if line.startswith('Active Bluetooth'):
network = False network = False
socket = False socket = False
bluetooth = True bluetooth = True
routing_table = False
continue
if line.startswith('Kernel IP routing table'):
network = False
socket = False
bluetooth = False
routing_table = True
continue continue
if line.startswith('Proto'): if line.startswith('Proto'):
@ -166,6 +194,11 @@ def parse(cleandata):
headers = header_text.split() headers = header_text.split()
continue continue
if line.startswith('Destination '):
header_text = normalize_route_headers(line)
headers = header_text.split()
continue
if network: if network:
raw_output.append(parse_network(headers, line)) raw_output.append(parse_network(headers, line))
continue continue
@ -178,4 +211,8 @@ def parse(cleandata):
# not implemented # not implemented
continue continue
if routing_table:
raw_output.append(parse_route(headers, line))
continue
return parse_post(raw_output) return parse_post(raw_output)

View File

@ -17,6 +17,7 @@ def normalize_route_headers(header):
header = header.lower() header = header.lower()
header = header.replace('flags', 'route_flags') header = header.replace('flags', 'route_flags')
header = header.replace('refs', 'route_refs') header = header.replace('refs', 'route_refs')
header = header.replace('netif', 'iface')
header = header.replace('-', '_') header = header.replace('-', '_')
return header return header

View File

@ -0,0 +1,5 @@
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
default gateway 0.0.0.0 UG 0 0 0 ens33
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.71.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33

View File

@ -0,0 +1,5 @@
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.71.2 0.0.0.0 UG 100 0 0 ens33
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.71.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33

View File

@ -0,0 +1,5 @@
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface MSS Window irtt
0.0.0.0 192.168.71.2 0.0.0.0 UG 100 0 0 ens33 0 0 0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker 0 0 0
192.168.71.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33 0 0 0

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long