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

349 lines
8.2 KiB
Markdown
Raw Normal View History

[Home](https://kellyjonbrazil.github.io/jc/)
2022-01-25 17:07:47 -08:00
<a id="jc.parsers.dig"></a>
2020-07-30 16:20:24 -07:00
2019-11-11 18:30:46 -08:00
# jc.parsers.dig
2022-01-25 17:07:47 -08:00
2022-03-04 13:27:39 -08:00
jc - JSON Convert `dig` command output parser
2019-11-11 18:30:46 -08:00
2021-05-10 10:13:52 -07:00
Options supported:
2022-01-19 17:30:14 -08:00
- `+noall +answer` options are supported in cases where only the answer
2022-01-25 18:03:34 -08:00
information is desired.
2021-05-10 10:13:52 -07:00
- `+axfr` option is supported on its own
2021-05-07 16:42:09 -07:00
2022-01-19 17:30:14 -08:00
The `when_epoch` calculated timestamp field is naive. (i.e. based on the
local time of the system the parser is run on)
2022-01-19 17:30:14 -08:00
The `when_epoch_utc` calculated timestamp field is timezone-aware and is
only available if the timezone field is UTC.
2020-08-05 13:32:59 -07:00
Usage (cli):
2019-12-12 09:47:14 -08:00
2022-01-25 18:03:34 -08:00
$ dig example.com | jc --dig
2020-08-05 16:51:58 -07:00
2022-01-25 18:03:34 -08:00
or
2020-08-05 16:51:58 -07:00
2022-01-25 18:03:34 -08:00
$ jc dig example.com
2019-11-11 18:30:46 -08:00
2020-08-05 13:32:59 -07:00
Usage (module):
2022-01-25 18:03:34 -08:00
import jc
result = jc.parse('dig', dig_command_output)
2022-01-18 14:18:12 -08:00
2021-04-08 12:42:01 -07:00
Schema:
2022-01-25 18:03:34 -08:00
[
{
"id": integer,
"opcode": string,
"status": string,
"flags": [
string
],
"query_num": integer,
"answer_num": integer,
"authority_num": integer,
"additional_num": integer,
"axfr": [
{
"name": string,
"class": string,
"type": string,
"ttl": integer,
"data": string
}
],
"opt_pseudosection": {
"edns": {
"version": integer,
"flags": [
string
],
"udp": integer
},
"cookie": string
},
"question": {
"name": string,
"class": string,
"type": string
},
"answer": [
{
"name": string,
"class": string,
"type": string,
"ttl": integer,
"data": string
}
],
"additional": [
{
"name": string,
"class": string,
"type": string,
"ttl": integer,
"data": string
}
],
"authority": [
{
"name": string,
"class": string,
"type": string,
"ttl": integer,
"data": string
}
],
"query_size": integer,
"query_time": integer, # in msec
"server": string,
"when": string,
"when_epoch": integer, # [0]
"when_epoch_utc": integer, # [1]
"rcvd": integer
"size": string
}
]
[0] naive timestamp if "when" field is parsable, else null
[1] timezone aware timestamp availabe for UTC, else null
Examples:
$ dig example.com | jc --dig -p
[
{
"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
}
]
$ dig cnn.com www.cnn.com @205.251.194.64 | jc --dig -p -r
[
{
"id": "46052",
"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": "40426",
"data": "93.184.216.34"
}
],
"query_time": "48 msec",
"server": "2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)",
"when": "Fri Apr 16 16:06:12 PDT 2021",
"rcvd": "56"
}
]
$ dig -x 1.1.1.1 | jc --dig -p
[
{
"id": 20785,
"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": "1.1.1.1.in-addr.arpa.",
"class": "IN",
"type": "PTR"
},
"answer": [
{
"name": "1.1.1.1.in-addr.arpa.",
"class": "IN",
"type": "PTR",
"ttl": 1800,
"data": "one.one.one.one."
}
],
"query_time": 40,
"server": "2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)",
"when": "Sat Apr 17 14:50:50 PDT 2021",
"rcvd": 78,
"when_epoch": 1618696250,
"when_epoch_utc": null
}
]
$ dig -x 1.1.1.1 | jc --dig -p -r
[
{
"id": "32644",
"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": "1.1.1.1.in-addr.arpa.",
"class": "IN",
"type": "PTR"
},
"answer": [
{
"name": "1.1.1.1.in-addr.arpa.",
"class": "IN",
"type": "PTR",
"ttl": "1800",
"data": "one.one.one.one."
}
],
"query_time": "52 msec",
"server": "2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)",
"when": "Sat Apr 17 14:51:46 PDT 2021",
"rcvd": "78"
}
]
$ dig +noall +answer cnn.com | jc --dig -p
[
{
"answer": [
{
"name": "cnn.com.",
"class": "IN",
"type": "A",
"ttl": 60,
"data": "151.101.193.67"
},
{
"name": "cnn.com.",
"class": "IN",
"type": "A",
"ttl": 60,
"data": "151.101.65.67"
},
{
"name": "cnn.com.",
"class": "IN",
"type": "A",
"ttl": 60,
"data": "151.101.1.67"
},
{
"name": "cnn.com.",
"class": "IN",
"type": "A",
"ttl": 60,
"data": "151.101.129.67"
}
]
}
]
2022-01-25 17:07:47 -08:00
<a id="jc.parsers.dig.parse"></a>
2022-03-05 12:15:14 -08:00
### parse
2022-01-25 17:07:47 -08:00
2019-11-11 18:30:46 -08:00
```python
2022-01-25 17:07:47 -08:00
def parse(data, raw=False, quiet=False)
2019-11-11 18:30:46 -08:00
```
2019-11-12 11:18:00 -08:00
Main text parsing function
2019-11-11 18:30:46 -08:00
2022-01-25 18:03:34 -08:00
Parameters:
2019-11-11 18:30:46 -08: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
2019-11-12 11:18:00 -08:00
2022-01-25 18:03:34 -08:00
Returns:
2019-11-12 11:18:00 -08:00
2022-01-25 18:03:34 -08:00
List of Dictionaries. Raw or processed structured data.
2019-11-11 18:30:46 -08:00
2022-01-25 19:18:54 -08:00
### Parser Information
2021-05-16 19:44:10 -07:00
Compatibility: linux, aix, freebsd, darwin, win32, cygwin
2022-02-07 15:44:54 -08:00
Version 2.3 by Kelly Brazil (kellyjonbrazil@gmail.com)