2020-07-30 16:20:24 -07:00
|
|
|
|
2020-07-23 16:44:57 -07:00
|
|
|
# jc.parsers.traceroute
|
|
|
|
jc - JSON CLI output utility traceroute Parser
|
|
|
|
|
2020-08-05 13:32:59 -07:00
|
|
|
Usage (cli):
|
2020-07-23 16:44:57 -07:00
|
|
|
|
|
|
|
specify --traceroute as the first argument if the piped input is coming from traceroute
|
|
|
|
|
2020-07-31 10:56:51 -07:00
|
|
|
Note: On some operating systems you will need to redirect STDERR to STDOUT for destination
|
|
|
|
info since the header line is sent to STDERR. A warning message will be printed to
|
|
|
|
STDERR if the header row is not found.
|
|
|
|
|
2020-07-23 16:44:57 -07:00
|
|
|
e.g. $ traceroute 8.8.8.8 2>&1 | jc --traceroute
|
|
|
|
|
2020-08-05 13:32:59 -07:00
|
|
|
Usage (module):
|
|
|
|
|
|
|
|
import jc.parsers.traceroute
|
|
|
|
result = jc.parsers.traceroute.parse(traceroute_command_output)
|
|
|
|
|
2020-07-23 16:44:57 -07:00
|
|
|
Compatibility:
|
|
|
|
|
|
|
|
'linux', 'darwin', 'freebsd'
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
$ traceroute google.com | jc --traceroute -p
|
|
|
|
{
|
|
|
|
"destination_ip": "216.58.194.46",
|
|
|
|
"destination_name": "google.com",
|
|
|
|
"hops": [
|
|
|
|
{
|
|
|
|
"hop": 1,
|
|
|
|
"probes": [
|
|
|
|
{
|
|
|
|
"annotation": null,
|
|
|
|
"asn": null,
|
|
|
|
"ip": "216.230.231.141",
|
|
|
|
"name": "216-230-231-141.static.houston.tx.oplink.net",
|
|
|
|
"rtt": 198.574
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"annotation": null,
|
|
|
|
"asn": null,
|
|
|
|
"ip": "216.230.231.141",
|
|
|
|
"name": "216-230-231-141.static.houston.tx.oplink.net",
|
|
|
|
"rtt": null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"annotation": null,
|
|
|
|
"asn": null,
|
|
|
|
"ip": "216.230.231.141",
|
|
|
|
"name": "216-230-231-141.static.houston.tx.oplink.net",
|
|
|
|
"rtt": 198.65
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
...
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
$ traceroute google.com | jc --traceroute -p -r
|
|
|
|
{
|
|
|
|
"destination_ip": "216.58.194.46",
|
|
|
|
"destination_name": "google.com",
|
|
|
|
"hops": [
|
|
|
|
{
|
|
|
|
"hop": "1",
|
|
|
|
"probes": [
|
|
|
|
{
|
|
|
|
"annotation": null,
|
|
|
|
"asn": null,
|
|
|
|
"ip": "216.230.231.141",
|
|
|
|
"name": "216-230-231-141.static.houston.tx.oplink.net",
|
|
|
|
"rtt": "198.574"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"annotation": null,
|
|
|
|
"asn": null,
|
|
|
|
"ip": "216.230.231.141",
|
|
|
|
"name": "216-230-231-141.static.houston.tx.oplink.net",
|
|
|
|
"rtt": null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"annotation": null,
|
|
|
|
"asn": null,
|
|
|
|
"ip": "216.230.231.141",
|
|
|
|
"name": "216-230-231-141.static.houston.tx.oplink.net",
|
|
|
|
"rtt": "198.650"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
...
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2020-07-30 16:20:24 -07:00
|
|
|
|
2020-07-23 16:44:57 -07:00
|
|
|
## info
|
|
|
|
```python
|
2020-07-30 16:20:24 -07:00
|
|
|
info()
|
2020-07-23 16:44:57 -07:00
|
|
|
```
|
|
|
|
|
2020-07-30 16:20:24 -07:00
|
|
|
|
2020-07-23 16:44:57 -07:00
|
|
|
## Hop
|
|
|
|
```python
|
2020-07-30 16:20:24 -07:00
|
|
|
Hop(idx)
|
2020-07-23 16:44:57 -07:00
|
|
|
```
|
|
|
|
|
2020-07-30 16:20:24 -07:00
|
|
|
|
2020-07-23 16:44:57 -07:00
|
|
|
## process
|
|
|
|
```python
|
|
|
|
process(proc_data)
|
|
|
|
```
|
|
|
|
|
|
|
|
Final processing to conform to the schema.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
|
|
|
|
proc_data: (dictionary) raw structured data to process
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
Dictionary. Structured data with the following schema:
|
|
|
|
|
|
|
|
{
|
|
|
|
"destination_ip": string,
|
|
|
|
"destination_name": string,
|
|
|
|
"hops": [
|
|
|
|
{
|
|
|
|
"hop": integer,
|
|
|
|
"probes": [
|
|
|
|
{
|
|
|
|
"annotation": string,
|
|
|
|
"asn": integer,
|
|
|
|
"ip": string,
|
|
|
|
"name": string,
|
|
|
|
"rtt": float
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2020-07-30 16:20:24 -07:00
|
|
|
|
2020-07-23 16:44:57 -07:00
|
|
|
## parse
|
|
|
|
```python
|
|
|
|
parse(data, raw=False, quiet=False)
|
|
|
|
```
|
|
|
|
|
|
|
|
Main text parsing function
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
|
|
|
|
data: (string) text data to parse
|
|
|
|
raw: (boolean) output preprocessed JSON if True
|
|
|
|
quiet: (boolean) suppress warning messages if True
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
Dictionary. Raw or processed structured data.
|
|
|
|
|