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

handle warning lines in the traceroute output

This commit is contained in:
Kelly Brazil
2020-07-22 15:02:02 -07:00
parent 5b444d4717
commit 066adfb764
7 changed files with 83 additions and 7 deletions

View File

@ -4,13 +4,16 @@ Usage:
specify --traceroute as the first argument if the piped input is coming from traceroute specify --traceroute as the first argument if the piped input is coming from traceroute
Note: on OSX and FreeBSD be sure to redirect STDERR to STDOUT since the header line is sent to STDERR
e.g. $ traceroute 8.8.8.8 2>&1 | jc --traceroute
Compatibility: Compatibility:
'linux', 'darwin', 'freebsd' 'linux', 'darwin', 'freebsd'
Examples: Examples:
$ traceroute | jc --traceroute -p $ traceroute www.cnn.com 2>&1 | jc --traceroute -p
[] []
$ traceroute | jc --traceroute -p -r $ traceroute | jc --traceroute -p -r
@ -211,9 +214,7 @@ class ParseError(Exception):
pass pass
########################################################################################
def process(proc_data): def process(proc_data):
""" """
@ -261,6 +262,19 @@ def parse(data, raw=False, quiet=False):
if jc.utils.has_data(data): if jc.utils.has_data(data):
# remove any warning lines
new_data = []
for data_line in data.splitlines():
if 'traceroute: Warning: ' not in data_line and 'traceroute6: Warning: ' not in data_line:
new_data.append(data_line)
else:
continue
data = '\n'.join(new_data)
# check if header row exists, otherwise raise exception
if not data.splitlines()[0].startswith('traceroute to ') and not data.splitlines()[0].startswith('traceroute6 to '):
raise ParseError('Traceroute header line not found. Be sure to redirect STDERR to STDOUT on OSX/FreeBSD.')
tr = loads(data) tr = loads(data)
hops = tr.hops hops = tr.hops
hops_list = [] hops_list = []
@ -268,18 +282,20 @@ def parse(data, raw=False, quiet=False):
if hops: if hops:
for hop in hops: for hop in hops:
hop_obj = {} hop_obj = {}
hop_obj['id'] = hop.idx hop_obj['hop'] = str(hop.idx)
probe_list = [] probe_list = []
if hop.probes: if hop.probes:
for probe in hop.probes: for probe in hop.probes:
probe_obj = { probe_obj = {
'annotation': probe.annotation, 'annotation': probe.annotation,
'asn': probe.asn, 'asn': None if probe.asn is None else str(probe.asn),
'ip': probe.ip, 'ip': probe.ip,
'name': probe.name, 'name': probe.name,
'rtt': None if probe.rtt is None else float(probe.rtt) 'rtt': None if probe.rtt is None else str(probe.rtt)
} }
probe_list.append(probe_obj) probe_list.append(probe_obj)
hop_obj['probes'] = probe_list hop_obj['probes'] = probe_list
hops_list.append(hop_obj) hops_list.append(hop_obj)

View File

@ -0,0 +1,32 @@
traceroute to www.cnn.com (151.101.197.67), 30 hops max, 60 byte packets
1 dsldevice.attlocal.net (192.168.1.254) 4.024 ms 3.683 ms 3.706 ms
2 76-220-24-1.lightspeed.sntcca.sbcglobal.net (76.220.24.1) 24.038 ms 23.911 ms 23.724 ms
3 * * *
4 12.122.149.186 (12.122.149.186) 42.273 ms 42.213 ms 42.083 ms
5 12.122.2.77 (12.122.2.77) 36.789 ms 43.691 ms 36.597 ms
6 sd2ca21crs.ip.att.net (12.122.2.94) 41.587 ms 40.240 ms 44.659 ms
7 12.123.215.161 (12.123.215.161) 37.858 ms 37.321 ms 37.092 ms
8 * * *
9 * * *
10 * * *
11 * * *
12 * * *
13 * * *
14 * * *
15 * * *
16 * * *
17 * * *
18 * * *
19 * * *
20 * * *
21 * * *
22 * * *
23 * * *
24 * * *
25 * * *
26 * * *
27 * * *
28 * * *
29 * * *
30 * * *

View File

@ -0,0 +1,5 @@
traceroute to 8.8.8.8 (8.8.8.8), 4 hops max, 52 byte packets
1 [AS198949] dsldevice (192.168.1.254) 6.070 ms 5.721 ms 5.269 ms
2 [AS0] 76-220-24-1.lightspeed.sntcca.sbcglobal.net (76.220.24.1) 160.025 ms 178.690 ms 33.759 ms
3 * * *
4 [AS7018] 12.122.149.186 (12.122.149.186) 37.783 ms 23.782 ms 24.958 ms

View File

@ -0,0 +1,5 @@
traceroute: Warning: cnn.com has multiple addresses; using 151.101.129.67
traceroute to cnn.com (151.101.129.67), 64 hops max, 52 byte packets
1 dsldevice (192.168.1.254) 4.478 ms 3.907 ms 4.849 ms
2 76-220-24-1.lightspeed.sntcca.sbcglobal.net (76.220.24.1) 23.530 ms 26.518 ms 23.480 ms
3 * *

View File

@ -0,0 +1,3 @@
1 dsldevice (192.168.1.254) 11.415 ms 3.934 ms 3.286 ms
2 76-220-24-1.lightspeed.sntcca.sbcglobal.net (76.220.24.1) 24.174 ms 20.817 ms 27.771 ms
3 * * *

View File

@ -0,0 +1,8 @@
traceroute6: Warning: turner-tls.map.fastly.net has multiple addresses; using 2a04:4e42:200::323
traceroute6 to turner-tls.map.fastly.net (2a04:4e42:200::323) from 2600:1700:bab0:d40:985:f00a:98bd:f142, 5 hops max, 12 byte packets
1 * * *
2 2001:506:6000:11b:71:156:212:143 27.635 ms 20.383 ms 23.438 ms
3 * * *
4 2001:1890:ff:ff08:12:242:117:16 20.118 ms 20.327 ms 21.213 ms
5 * * *

View File

@ -0,0 +1,7 @@
traceroute6 to turner-tls.map.fastly.net (2a04:4e42:200::323) from 2600:1700:bab0:d40:985:f00a:98bd:f142, 5 hops max, 12 byte packets
1 * * *
2 2001:506:6000:11b:71:156:212:143 27.635 ms 20.383 ms 23.438 ms
3 * * *
4 2001:1890:ff:ff08:12:242:117:16 20.118 ms 20.327 ms 21.213 ms
5 * * *