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

356 lines
8.3 KiB
Markdown
Raw Normal View History

[Home](https://kellyjonbrazil.github.io/jc/)
2020-07-30 16:20:24 -07:00
2019-11-11 18:30:46 -08:00
# jc.parsers.dig
2020-08-05 16:51:58 -07:00
jc - JSON CLI output utility `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
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
2020-08-05 16:51:58 -07:00
$ dig example.com | jc --dig
or
$ jc dig example.com
2019-11-11 18:30:46 -08:00
2020-08-05 13:32:59 -07:00
Usage (module):
2022-01-18 14:18:12 -08:00
import jc
result = jc.parse('dig', dig_command_output)
or
2020-08-05 13:32:59 -07:00
import jc.parsers.dig
result = jc.parsers.dig.parse(dig_command_output)
2021-04-08 12:42:01 -07:00
Schema:
[
{
"id": integer,
"opcode": string,
"status": string,
2021-04-08 12:42:01 -07:00
"flags": [
string
2021-04-08 12:42:01 -07:00
],
"query_num": integer,
"answer_num": integer,
"authority_num": integer,
"additional_num": integer,
2021-04-08 12:42:01 -07:00
"axfr": [
{
"name": string,
"class": string,
"type": string,
"ttl": integer,
"data": string
2021-04-08 12:42:01 -07:00
}
],
"opt_pseudosection": {
2021-04-18 16:42:34 -07:00
"edns": {
"version": integer,
"flags": [
string
2021-04-18 16:42:34 -07:00
],
"udp": integer
},
"cookie": string
},
2021-04-08 12:42:01 -07:00
"question": {
"name": string,
"class": string,
"type": string
2021-04-08 12:42:01 -07:00
},
"answer": [
{
"name": string,
"class": string,
"type": string,
"ttl": integer,
"data": string
}
],
"additional": [
{
"name": string,
"class": string,
"type": string,
"ttl": integer,
"data": string
2021-04-08 12:42:01 -07:00
}
],
"authority": [
{
"name": string,
"class": string,
"type": string,
"ttl": integer,
"data": string
2021-04-08 12:42:01 -07:00
}
],
"query_size": integer,
"query_time": integer, # in msec
"server": string,
"when": string,
2022-01-19 17:30:14 -08:00
"when_epoch": integer, # [0]
"when_epoch_utc": integer, # [1]
"rcvd": integer
"size": string
2021-04-08 12:42:01 -07:00
}
]
2022-01-19 21:32:21 -08:00
[0] naive timestamp if "when" field is parsable, else null
2022-01-19 17:30:14 -08:00
[1] timezone aware timestamp availabe for UTC, else null
2019-11-11 18:30:46 -08:00
Examples:
$ dig example.com | jc --dig -p
2019-11-11 18:30:46 -08:00
[
{
"id": 2951,
2019-11-11 18:30:46 -08:00
"opcode": "QUERY",
"status": "NOERROR",
2019-11-12 07:19:01 -08:00
"flags": [
"qr",
"rd",
"ra"
],
"query_num": 1,
"answer_num": 1,
2019-11-12 07:19:01 -08:00
"authority_num": 0,
"additional_num": 1,
"opt_pseudosection": {
"edns": {
"version": 0,
"flags": [],
"udp": 4096
2019-11-12 07:19:01 -08:00
}
},
2019-11-12 07:19:01 -08:00
"question": {
"name": "example.com.",
2019-11-12 07:19:01 -08:00
"class": "IN",
"type": "A"
},
"answer": [
{
"name": "example.com.",
2019-11-12 07:19:01 -08:00
"class": "IN",
"type": "A",
"ttl": 39302,
"data": "93.184.216.34"
2019-11-12 07:19:01 -08:00
}
],
"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-12 07:19:01 -08:00
}
]
$ dig cnn.com www.cnn.com @205.251.194.64 | jc --dig -p -r
[
{
"id": "46052",
2019-11-12 07:19:01 -08:00
"opcode": "QUERY",
"status": "NOERROR",
"flags": [
"qr",
"rd",
"ra"
],
2019-11-11 18:30:46 -08:00
"query_num": "1",
"answer_num": "1",
2019-11-11 18:30:46 -08:00
"authority_num": "0",
"additional_num": "1",
"opt_pseudosection": {
"edns": {
"version": "0",
"flags": [],
"udp": "4096"
2019-11-11 18:30:46 -08:00
}
},
2019-11-11 18:30:46 -08:00
"question": {
"name": "example.com.",
2019-11-11 18:30:46 -08:00
"class": "IN",
"type": "A"
},
"answer": [
{
"name": "example.com.",
2019-11-11 18:30:46 -08:00
"class": "IN",
"type": "A",
"ttl": "40426",
"data": "93.184.216.34"
2019-11-11 18:30:46 -08:00
}
],
"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"
2019-11-11 18:30:46 -08:00
}
]
$ dig -x 1.1.1.1 | jc --dig -p
[
{
2021-04-17 15:02:45 -07:00
"id": 20785,
2019-11-11 18:30:46 -08:00
"opcode": "QUERY",
"status": "NOERROR",
2019-11-12 07:19:01 -08:00
"flags": [
"qr",
"rd",
"ra"
],
"query_num": 1,
"answer_num": 1,
"authority_num": 0,
"additional_num": 1,
2021-04-17 15:02:45 -07:00
"opt_pseudosection": {
"edns": {
"version": 0,
"flags": [],
"udp": 4096
}
},
2019-11-12 07:19:01 -08:00
"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,
2019-11-12 07:19:01 -08:00
"data": "one.one.one.one."
}
],
2021-04-17 15:02:45 -07:00
"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,
2021-04-17 15:02:45 -07:00
"when_epoch": 1618696250,
"when_epoch_utc": null
2019-11-12 07:19:01 -08:00
}
]
$ dig -x 1.1.1.1 | jc --dig -p -r
[
{
2021-04-17 15:02:45 -07:00
"id": "32644",
2019-11-12 07:19:01 -08:00
"opcode": "QUERY",
"status": "NOERROR",
"flags": [
"qr",
"rd",
"ra"
],
2019-11-11 18:30:46 -08:00
"query_num": "1",
"answer_num": "1",
"authority_num": "0",
"additional_num": "1",
2021-04-17 15:02:45 -07:00
"opt_pseudosection": {
"edns": {
"version": "0",
"flags": [],
"udp": "4096"
}
},
2019-11-11 18:30:46 -08:00
"question": {
"name": "1.1.1.1.in-addr.arpa.",
"class": "IN",
"type": "PTR"
},
"answer": [
{
2019-11-12 07:19:01 -08:00
"name": "1.1.1.1.in-addr.arpa.",
2019-11-11 18:30:46 -08:00
"class": "IN",
"type": "PTR",
2019-11-12 07:19:01 -08:00
"ttl": "1800",
2019-11-11 18:30:46 -08:00
"data": "one.one.one.one."
}
],
2021-04-17 15:02:45 -07:00
"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",
2019-11-12 07:19:01 -08:00
"rcvd": "78"
2019-11-11 18:30:46 -08:00
}
]
2021-05-07 16:42:09 -07:00
$ 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"
}
]
}
]
2020-07-30 16:20:24 -07:00
2019-12-14 23:35:42 -08:00
## info
```python
2020-07-30 16:20:24 -07:00
info()
2019-12-14 23:35:42 -08:00
```
2021-04-08 12:42:01 -07:00
Provides parser metadata (version, author, etc.)
2020-07-30 16:20:24 -07:00
2019-11-11 18:30:46 -08:00
## parse
```python
parse(data, raw=False, quiet=False)
```
2019-11-12 11:18:00 -08:00
Main text parsing function
2019-11-11 18:30:46 -08:00
2019-11-12 11:18:00 -08:00
Parameters:
2019-11-11 18:30:46 -08:00
2019-11-12 11:18:00 -08:00
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
quiet: (boolean) suppress warning messages if True
Returns:
2021-01-04 18:01:16 -08:00
List of Dictionaries. Raw or processed structured data.
2019-11-11 18:30:46 -08:00
## Parser Information
2021-05-16 19:44:10 -07:00
Compatibility: linux, aix, freebsd, darwin, win32, cygwin
2021-12-01 16:12:51 -08:00
Version 2.2 by Kelly Brazil (kellyjonbrazil@gmail.com)