mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
147 lines
3.4 KiB
Markdown
147 lines
3.4 KiB
Markdown
[Home](https://kellyjonbrazil.github.io/jc/)
|
|
<a id="jc.parsers.traceroute"></a>
|
|
|
|
# jc.parsers.traceroute
|
|
|
|
jc - JSON Convert `traceroute` command output parser
|
|
|
|
Supports `traceroute` and `traceroute6` output.
|
|
|
|
> 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.
|
|
>
|
|
> e.g. `$ traceroute 8.8.8.8 2>&1 | jc --traceroute`
|
|
|
|
Usage (cli):
|
|
|
|
$ traceroute 1.2.3.4 | jc --traceroute
|
|
|
|
or
|
|
|
|
$ jc traceroute 1.2.3.4
|
|
|
|
Usage (module):
|
|
|
|
import jc
|
|
result = jc.parse('traceroute', traceroute_command_output)
|
|
|
|
Schema:
|
|
|
|
{
|
|
"destination_ip": string,
|
|
"destination_name": string,
|
|
"hops": [
|
|
{
|
|
"hop": integer,
|
|
"probes": [
|
|
{
|
|
"annotation": string,
|
|
"asn": integer,
|
|
"ip": string,
|
|
"name": string,
|
|
"rtt": float
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
|
|
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"
|
|
}
|
|
]
|
|
},
|
|
...
|
|
]
|
|
}
|
|
|
|
<a id="jc.parsers.traceroute.parse"></a>
|
|
|
|
### parse
|
|
|
|
```python
|
|
def parse(data, raw=False, quiet=False)
|
|
```
|
|
|
|
Main text parsing function
|
|
|
|
Parameters:
|
|
|
|
data: (string) text data to parse
|
|
raw: (boolean) unprocessed output if True
|
|
quiet: (boolean) suppress warning messages if True
|
|
|
|
Returns:
|
|
|
|
Dictionary. Raw or processed structured data.
|
|
|
|
### Parser Information
|
|
Compatibility: linux, darwin, freebsd
|
|
|
|
Version 1.6 by Kelly Brazil (kellyjonbrazil@gmail.com)
|