2020-07-30 16:20:24 -07:00
|
|
|
|
2019-11-11 18:30:46 -08:00
|
|
|
# jc
|
|
|
|
JC - JSON CLI output utility
|
|
|
|
|
|
|
|
* kellyjonbrazil@gmail.com
|
|
|
|
|
2022-01-19 10:31:46 -08:00
|
|
|
This package serializes the output of many standard unix command line tools
|
|
|
|
to JSON format.
|
2019-11-11 18:30:46 -08:00
|
|
|
|
2022-01-19 10:31:46 -08:00
|
|
|
For documentation on each parser, see the
|
|
|
|
[documentation site](https://kellyjonbrazil.github.io/jc/).
|
2020-08-11 06:36:30 -07:00
|
|
|
|
2019-11-11 18:30:46 -08:00
|
|
|
CLI Example:
|
|
|
|
|
2021-04-16 16:30:04 -07:00
|
|
|
$ dig example.com | jc --dig -p
|
2019-11-11 18:30:46 -08:00
|
|
|
[
|
|
|
|
{
|
2021-04-16 16:30:04 -07:00
|
|
|
"id": 2951,
|
|
|
|
"opcode": "QUERY",
|
|
|
|
"status": "NOERROR",
|
|
|
|
"flags": [
|
|
|
|
"qr",
|
|
|
|
"rd",
|
|
|
|
"ra"
|
|
|
|
],
|
|
|
|
"query_num": 1,
|
|
|
|
"answer_num": 1,
|
|
|
|
"authority_num": 0,
|
|
|
|
"additional_num": 1,
|
|
|
|
"opt_pseudosection": {
|
|
|
|
"edns": {
|
|
|
|
"version": 0,
|
|
|
|
"flags": [],
|
|
|
|
"udp": 4096
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"question": {
|
|
|
|
"name": "example.com.",
|
|
|
|
"class": "IN",
|
|
|
|
"type": "A"
|
|
|
|
},
|
|
|
|
"answer": [
|
|
|
|
{
|
|
|
|
"name": "example.com.",
|
|
|
|
"class": "IN",
|
|
|
|
"type": "A",
|
|
|
|
"ttl": 39302,
|
|
|
|
"data": "93.184.216.34"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"query_time": 49,
|
|
|
|
"server": "2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)",
|
|
|
|
"when": "Fri Apr 16 16:05:10 PDT 2021",
|
|
|
|
"rcvd": 56,
|
|
|
|
"when_epoch": 1618614310,
|
|
|
|
"when_epoch_utc": null
|
|
|
|
}
|
2019-11-11 18:30:46 -08:00
|
|
|
]
|
|
|
|
|
|
|
|
Module Example:
|
|
|
|
|
2022-01-18 13:40:09 -08:00
|
|
|
>>> import subprocess
|
|
|
|
>>> import jc
|
|
|
|
>>>
|
2022-01-19 10:31:46 -08:00
|
|
|
>>> cmd_output = subprocess.check_output(['dig', 'example.com'],
|
|
|
|
text=True)
|
2022-01-18 13:40:09 -08:00
|
|
|
>>> data = jc.parse('dig', cmd_output)
|
2019-11-11 18:30:46 -08:00
|
|
|
>>>
|
2022-01-18 13:40:09 -08:00
|
|
|
>>> data
|
2022-01-19 10:31:46 -08:00
|
|
|
[{'id': 64612, 'opcode': 'QUERY', 'status': 'NOERROR', ...}]
|
2022-01-18 13:40:09 -08:00
|
|
|
|
2022-01-19 10:31:46 -08:00
|
|
|
Alternatively, you can bypass the high-level API and call the parser
|
|
|
|
modules directly:
|
2022-01-18 13:40:09 -08:00
|
|
|
|
2021-09-10 14:27:50 -07:00
|
|
|
>>> import subprocess
|
|
|
|
>>> import jc.parsers.dig
|
|
|
|
>>>
|
2022-01-19 10:31:46 -08:00
|
|
|
>>> cmd_output = subprocess.check_output(['dig', 'example.com'],
|
|
|
|
text=True)
|
2021-09-10 14:27:50 -07:00
|
|
|
>>> data = jc.parsers.dig.parse(cmd_output)
|
2019-11-11 18:30:46 -08:00
|
|
|
>>>
|
2021-09-10 14:27:50 -07:00
|
|
|
>>> data
|
2022-01-19 10:31:46 -08:00
|
|
|
[{'id': 64612, 'opcode': 'QUERY', 'status': 'NOERROR', ...}]
|
2019-11-11 18:30:46 -08:00
|
|
|
|
2022-01-19 10:31:46 -08:00
|
|
|
To get a list of all available parser module names, use
|
|
|
|
`jc.parser_mod_list()`. For a list of plugin parser module names only,
|
|
|
|
use the `jc.plugin_parser_mod_list()` function.
|
2022-01-18 13:46:11 -08:00
|
|
|
|