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

214 lines
4.5 KiB
Markdown
Raw Normal View History

[Home](https://kellyjonbrazil.github.io/jc/)
2022-01-25 17:07:47 -08:00
<a id="jc.parsers.traceroute"></a>
2020-07-30 16:20:24 -07:00
2020-07-23 16:44:57 -07:00
# jc.parsers.traceroute
2022-01-25 17:07:47 -08:00
2020-08-05 16:51:58 -07:00
jc - JSON CLI output utility `traceroute` command output parser
Supports `traceroute` and `traceroute6` output.
2022-01-19 17:30:14 -08:00
Note: On some operating systems you will need to redirect `STDERR` to
2022-01-25 17:07:47 -08:00
`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-08-05 16:51:58 -07:00
2022-01-25 17:07:47 -08:00
e.g. `$ traceroute 8.8.8.8 2>&1 | jc --traceroute`
2020-07-23 16:44:57 -07:00
2020-08-05 13:32:59 -07:00
Usage (cli):
2020-07-23 16:44:57 -07:00
2022-01-25 17:07:47 -08:00
$ traceroute 1.2.3.4 | jc --traceroute
2020-07-23 16:44:57 -07:00
2022-01-25 17:07:47 -08:00
or
2020-07-31 10:56:51 -07:00
2022-01-25 17:07:47 -08:00
$ jc traceroute 1.2.3.4
2020-07-23 16:44:57 -07:00
2020-08-05 13:32:59 -07:00
Usage (module):
2022-01-25 17:07:47 -08:00
import jc
result = jc.parse('traceroute', traceroute_command_output)
2022-01-18 15:38:03 -08:00
2022-01-25 17:07:47 -08:00
or
2022-01-18 15:38:03 -08:00
2022-01-25 17:07:47 -08:00
import jc.parsers.traceroute
result = jc.parsers.traceroute.parse(traceroute_command_output)
2020-08-05 13:32:59 -07:00
2021-04-08 15:52:49 -07:00
Schema:
2022-01-25 17:07:47 -08:00
{
"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.info"></a>
## info Objects
2020-07-23 16:44:57 -07:00
```python
2022-01-25 17:07:47 -08:00
class info()
2020-07-23 16:44:57 -07:00
```
2022-01-25 17:07:47 -08:00
2021-04-08 15:52:49 -07:00
Provides parser metadata (version, author, etc.)
2020-07-30 16:20:24 -07:00
2022-01-25 17:07:47 -08:00
<a id="jc.parsers.traceroute.__version__"></a>
#### \_\_version\_\_
Copyright (C) 2015 Luis Benitez
Parses the output of a traceroute execution into an AST (Abstract Syntax Tree).
The MIT License (MIT)
Copyright (c) 2014 Luis Benitez
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
<a id="jc.parsers.traceroute._Hop"></a>
## \_Hop Objects
```python
class _Hop(object)
```
<a id="jc.parsers.traceroute._Hop.add_probe"></a>
#### add\_probe
```python
def add_probe(probe)
```
Adds a Probe instance to this hop's results.
<a id="jc.parsers.traceroute.parse"></a>
#### parse
2020-07-23 16:44:57 -07:00
```python
2022-01-25 17:07:47 -08:00
def parse(data, raw=False, quiet=False)
2020-07-23 16:44:57 -07:00
```
Main text parsing function
2022-01-25 17:07:47 -08:00
**Arguments**:
2020-07-23 16:44:57 -07:00
2022-01-25 17:07:47 -08:00
- `data` - (string) text data to parse
- `raw` - (boolean) unprocessed output if True
- `quiet` - (boolean) suppress warning messages if True
2020-07-23 16:44:57 -07:00
2022-01-25 17:07:47 -08:00
**Returns**:
2020-07-23 16:44:57 -07:00
2022-01-25 17:07:47 -08:00
Dictionary. Raw or processed structured data.
2020-07-23 16:44:57 -07:00
## Parser Information
Compatibility: linux, darwin, freebsd
2021-12-01 16:12:51 -08:00
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)