2021-04-09 10:36:42 -07:00
|
|
|
[Home](https://kellyjonbrazil.github.io/jc/)
|
2022-01-25 17:07:47 -08:00
|
|
|
<a id="jc.parsers.ping"></a>
|
2020-07-30 16:20:24 -07:00
|
|
|
|
2020-07-18 12:35:46 -07:00
|
|
|
# jc.parsers.ping
|
2022-01-25 17:07:47 -08:00
|
|
|
|
2022-03-04 13:27:39 -08:00
|
|
|
jc - JSON Convert `ping` command output parser
|
2020-08-05 16:51:58 -07:00
|
|
|
|
|
|
|
Supports `ping` and `ping6` output.
|
2020-07-18 12:35:46 -07:00
|
|
|
|
2020-08-05 13:32:59 -07:00
|
|
|
Usage (cli):
|
2020-07-18 12:35:46 -07:00
|
|
|
|
2022-05-26 15:11:58 -07:00
|
|
|
> Note: Use the ping `-c` (count) option, otherwise data will not be
|
|
|
|
> piped to `jc`.
|
2020-08-05 16:51:58 -07:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
$ ping -c 3 1.2.3.4 | jc --ping
|
2020-08-05 16:51:58 -07:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
or
|
2020-07-18 12:35:46 -07:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
$ jc ping -c 3 1.2.3.4
|
2020-07-19 15:30:54 -07:00
|
|
|
|
2020-08-05 13:32:59 -07:00
|
|
|
Usage (module):
|
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
import jc
|
|
|
|
result = jc.parse('ping', ping_command_output)
|
2022-01-18 15:38:03 -08:00
|
|
|
|
2021-04-08 15:52:49 -07:00
|
|
|
Schema:
|
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
{
|
|
|
|
"source_ip": string,
|
|
|
|
"destination_ip": string,
|
|
|
|
"data_bytes": integer,
|
|
|
|
"pattern": string, # null if not set
|
|
|
|
"destination": string,
|
|
|
|
"packets_transmitted": integer,
|
|
|
|
"packets_received": integer,
|
|
|
|
"packet_loss_percent": float,
|
|
|
|
"duplicates": integer,
|
|
|
|
"round_trip_ms_min": float,
|
|
|
|
"round_trip_ms_avg": float,
|
|
|
|
"round_trip_ms_max": float,
|
|
|
|
"round_trip_ms_stddev": float,
|
|
|
|
"responses": [
|
|
|
|
{
|
|
|
|
"type": string, # [0]
|
|
|
|
"unparsed_line": string, # [1]
|
|
|
|
"timestamp": float,
|
|
|
|
"bytes": integer,
|
|
|
|
"response_ip": string,
|
|
|
|
"icmp_seq": integer,
|
|
|
|
"ttl": integer,
|
|
|
|
"time_ms": float,
|
|
|
|
"duplicate": boolean,
|
|
|
|
"vr": integer, # [2]
|
|
|
|
"hl": integer, # [2]
|
|
|
|
"tos": integer, # [2]
|
|
|
|
"len": integer, # [2]
|
|
|
|
"id": integer, # [2]
|
|
|
|
"flg": integer, # [2]
|
|
|
|
"off": integer, # [2]
|
|
|
|
"pro": integer, # [2]
|
|
|
|
"cks": ingeger, # [2]
|
|
|
|
"src": string,
|
|
|
|
"dst": string
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
[0] 'reply', 'timeout', 'unparsable_line', etc. See
|
|
|
|
`_error_type.type_map` for all options
|
|
|
|
[1] only if an 'unparsable_line' type
|
|
|
|
[2] hex value converted to decimal
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
$ ping -c 3 -p ff cnn.com | jc --ping -p
|
|
|
|
{
|
|
|
|
"destination_ip": "151.101.1.67",
|
|
|
|
"data_bytes": 56,
|
|
|
|
"pattern": "0xff",
|
|
|
|
"destination": "cnn.com",
|
|
|
|
"packets_transmitted": 3,
|
|
|
|
"packets_received": 3,
|
|
|
|
"packet_loss_percent": 0.0,
|
|
|
|
"duplicates": 0,
|
|
|
|
"round_trip_ms_min": 28.015,
|
|
|
|
"round_trip_ms_avg": 32.848,
|
|
|
|
"round_trip_ms_max": 39.376,
|
|
|
|
"round_trip_ms_stddev": 4.79,
|
|
|
|
"responses": [
|
|
|
|
{
|
|
|
|
"type": "reply",
|
|
|
|
"bytes": 64,
|
|
|
|
"response_ip": "151.101.1.67",
|
|
|
|
"icmp_seq": 0,
|
|
|
|
"ttl": 59,
|
|
|
|
"time_ms": 28.015,
|
|
|
|
"duplicate": false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "reply",
|
|
|
|
"bytes": 64,
|
|
|
|
"response_ip": "151.101.1.67",
|
|
|
|
"icmp_seq": 1,
|
|
|
|
"ttl": 59,
|
|
|
|
"time_ms": 39.376,
|
|
|
|
"duplicate": false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "reply",
|
|
|
|
"bytes": 64,
|
|
|
|
"response_ip": "151.101.1.67",
|
|
|
|
"icmp_seq": 2,
|
|
|
|
"ttl": 59,
|
|
|
|
"time_ms": 31.153,
|
|
|
|
"duplicate": false
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
$ ping -c 3 -p ff cnn.com | jc --ping -p -r
|
|
|
|
{
|
|
|
|
"destination_ip": "151.101.129.67",
|
|
|
|
"data_bytes": "56",
|
|
|
|
"pattern": "0xff",
|
|
|
|
"destination": "cnn.com",
|
|
|
|
"packets_transmitted": "3",
|
|
|
|
"packets_received": "3",
|
|
|
|
"packet_loss_percent": "0.0",
|
|
|
|
"duplicates": "0",
|
|
|
|
"round_trip_ms_min": "25.078",
|
|
|
|
"round_trip_ms_avg": "29.543",
|
|
|
|
"round_trip_ms_max": "32.553",
|
|
|
|
"round_trip_ms_stddev": "3.221",
|
|
|
|
"responses": [
|
|
|
|
{
|
|
|
|
"type": "reply",
|
|
|
|
"bytes": "64",
|
|
|
|
"response_ip": "151.101.129.67",
|
|
|
|
"icmp_seq": "0",
|
|
|
|
"ttl": "59",
|
|
|
|
"time_ms": "25.078",
|
|
|
|
"duplicate": false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "reply",
|
|
|
|
"bytes": "64",
|
|
|
|
"response_ip": "151.101.129.67",
|
|
|
|
"icmp_seq": "1",
|
|
|
|
"ttl": "59",
|
|
|
|
"time_ms": "30.999",
|
|
|
|
"duplicate": false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "reply",
|
|
|
|
"bytes": "64",
|
|
|
|
"response_ip": "151.101.129.67",
|
|
|
|
"icmp_seq": "2",
|
|
|
|
"ttl": "59",
|
|
|
|
"time_ms": "32.553",
|
|
|
|
"duplicate": false
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2022-01-25 17:07:47 -08:00
|
|
|
|
|
|
|
<a id="jc.parsers.ping.parse"></a>
|
|
|
|
|
2022-03-05 12:15:14 -08:00
|
|
|
### parse
|
2022-01-25 17:07:47 -08:00
|
|
|
|
2020-07-18 12:35:46 -07:00
|
|
|
```python
|
2022-01-25 17:07:47 -08:00
|
|
|
def parse(data, raw=False, quiet=False)
|
2020-07-18 12:35:46 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
Main text parsing function
|
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
Parameters:
|
2020-07-18 12:35:46 -07:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
data: (string) text data to parse
|
|
|
|
raw: (boolean) unprocessed output if True
|
|
|
|
quiet: (boolean) suppress warning messages if True
|
2020-07-18 12:35:46 -07:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
Returns:
|
2020-07-18 12:35:46 -07:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
Dictionary. Raw or processed structured data.
|
2020-07-18 12:35:46 -07:00
|
|
|
|
2022-01-25 19:18:54 -08:00
|
|
|
### Parser Information
|
2021-04-09 10:36:42 -07:00
|
|
|
Compatibility: linux, darwin, freebsd
|
|
|
|
|
2022-07-16 20:52:19 -07:00
|
|
|
Version 1.8 by Kelly Brazil (kellyjonbrazil@gmail.com)
|