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

426 lines
9.3 KiB
Markdown
Raw Normal View History

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
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):
import jc.parsers.dig
result = jc.parsers.dig.parse(dig_command_output)
2019-12-12 09:21:20 -08:00
Compatibility:
2019-12-12 09:47:14 -08:00
2019-12-12 09:21:20 -08:00
'linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'
2019-11-11 18:30:46 -08:00
Examples:
$ dig cnn.com www.cnn.com @205.251.194.64 | jc --dig -p
[
{
2019-11-12 07:19:01 -08:00
"id": 34128,
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": 4,
"authority_num": 0,
"additional_num": 1,
"question": {
"name": "cnn.com.",
"class": "IN",
"type": "A"
},
"answer": [
{
"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.193.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"
}
],
"query_time": 37,
"server": "2600",
"when": "Tue Nov 12 07:14:42 PST 2019",
"rcvd": 100
},
{
"id": 15273,
"opcode": "QUERY",
"status": "NOERROR",
"flags": [
"qr",
"aa",
"rd"
],
"query_num": 1,
"answer_num": 1,
"authority_num": 4,
"additional_num": 1,
"question": {
"name": "www.cnn.com.",
"class": "IN",
"type": "A"
},
"answer": [
{
"name": "www.cnn.com.",
"class": "IN",
"type": "CNAME",
"ttl": 300,
"data": "turner-tls.map.fastly.net."
}
],
"authority": [
{
"name": "cnn.com.",
"class": "IN",
"type": "NS",
"ttl": 3600,
"data": "ns-1086.awsdns-07.org."
},
{
"name": "cnn.com.",
"class": "IN",
"type": "NS",
"ttl": 3600,
"data": "ns-1630.awsdns-11.co.uk."
},
{
"name": "cnn.com.",
"class": "IN",
"type": "NS",
"ttl": 3600,
"data": "ns-47.awsdns-05.com."
},
{
"name": "cnn.com.",
"class": "IN",
"type": "NS",
"ttl": 3600,
"data": "ns-576.awsdns-08.net."
}
],
"query_time": 23,
"server": "205.251.194.64#53(205.251.194.64)",
"when": "Tue Nov 12 07:14:42 PST 2019",
"rcvd": 212
}
]
$ dig cnn.com www.cnn.com @205.251.194.64 | jc --dig -p -r
[
{
"id": "23843",
"opcode": "QUERY",
"status": "NOERROR",
"flags": [
"qr",
"rd",
"ra"
],
2019-11-11 18:30:46 -08:00
"query_num": "1",
"answer_num": "4",
"authority_num": "0",
"additional_num": "1",
"question": {
"name": "cnn.com.",
"class": "IN",
"type": "A"
},
"answer": [
{
"name": "cnn.com.",
"class": "IN",
"type": "A",
2019-11-12 07:19:01 -08:00
"ttl": "30",
2019-11-11 18:30:46 -08:00
"data": "151.101.193.67"
},
{
"name": "cnn.com.",
"class": "IN",
"type": "A",
2019-11-12 07:19:01 -08:00
"ttl": "30",
2019-11-11 18:30:46 -08:00
"data": "151.101.1.67"
},
{
"name": "cnn.com.",
"class": "IN",
"type": "A",
2019-11-12 07:19:01 -08:00
"ttl": "30",
"data": "151.101.65.67"
2019-11-11 18:30:46 -08:00
},
{
"name": "cnn.com.",
"class": "IN",
"type": "A",
2019-11-12 07:19:01 -08:00
"ttl": "30",
"data": "151.101.129.67"
2019-11-11 18:30:46 -08:00
}
],
2019-11-12 07:19:01 -08:00
"query_time": "24 msec",
"server": "192.168.1.254#53(192.168.1.254)",
"when": "Tue Nov 12 07:16:19 PST 2019",
2019-11-11 18:30:46 -08:00
"rcvd": "100"
},
{
2019-11-12 07:19:01 -08:00
"id": "8266",
2019-11-11 18:30:46 -08:00
"opcode": "QUERY",
"status": "NOERROR",
2019-11-12 07:19:01 -08:00
"flags": [
"qr",
"aa",
"rd"
],
2019-11-11 18:30:46 -08:00
"query_num": "1",
"answer_num": "1",
"authority_num": "4",
"additional_num": "1",
"question": {
"name": "www.cnn.com.",
"class": "IN",
"type": "A"
},
"answer": [
{
"name": "www.cnn.com.",
"class": "IN",
"type": "CNAME",
"ttl": "300",
"data": "turner-tls.map.fastly.net."
}
],
"authority": [
{
"name": "cnn.com.",
"class": "IN",
"type": "NS",
"ttl": "3600",
"data": "ns-1086.awsdns-07.org."
},
{
"name": "cnn.com.",
"class": "IN",
"type": "NS",
"ttl": "3600",
"data": "ns-1630.awsdns-11.co.uk."
},
{
"name": "cnn.com.",
"class": "IN",
"type": "NS",
"ttl": "3600",
"data": "ns-47.awsdns-05.com."
},
{
"name": "cnn.com.",
"class": "IN",
"type": "NS",
"ttl": "3600",
"data": "ns-576.awsdns-08.net."
}
],
2019-11-12 07:19:01 -08:00
"query_time": "26 msec",
2019-11-11 18:30:46 -08:00
"server": "205.251.194.64#53(205.251.194.64)",
2019-11-12 07:19:01 -08:00
"when": "Tue Nov 12 07:16:19 PST 2019",
2019-11-11 18:30:46 -08:00
"rcvd": "212"
}
]
$ dig -x 1.1.1.1 | jc --dig -p
[
{
2019-11-12 07:19:01 -08:00
"id": 34898,
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,
"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": 952,
"data": "one.one.one.one."
}
],
"query_time": 103,
"server": "2600",
"when": "Tue Nov 12 07:15:33 PST 2019",
"rcvd": 78
}
]
$ dig -x 1.1.1.1 | jc --dig -p -r
[
{
"id": "50986",
"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",
"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."
}
],
2019-11-12 07:19:01 -08:00
"query_time": "38 msec",
"server": "2600",
"when": "Tue Nov 12 07:17:19 PST 2019",
"rcvd": "78"
2019-11-11 18:30:46 -08:00
}
]
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
```
2020-07-30 16:20:24 -07:00
2019-11-11 18:30:46 -08:00
## process
```python
process(proc_data)
```
2019-11-12 11:28:10 -08:00
Final processing to conform to the schema.
Parameters:
2019-11-13 08:04:40 -08:00
proc_data: (dictionary) raw structured data to process
2019-11-12 11:28:10 -08:00
Returns:
2019-12-17 09:56:09 -08:00
List of dictionaries. Structured data with the following schema:
2019-11-11 18:30:46 -08:00
[
{
"id": integer,
"opcode": string,
"status": string,
"flags": [
string
],
"query_num": integer,
"answer_num": integer,
"authority_num": integer,
"additional_num": integer,
2020-03-27 07:31:08 -07:00
"axfr": [
{
"name": string,
"class": string,
"type": string,
"ttl": integer,
"data": string
}
],
2019-11-11 18:30:46 -08:00
"question": {
"name": string,
"class": string,
"type": string
},
"answer": [
{
"name": string,
"class": string,
"type": string,
"ttl": integer,
"data": string
}
],
"authority": [
{
"name": string,
"class": string,
"type": string,
"ttl": integer,
"data": string
}
],
"query_time": integer, # in msec
"server": string,
"when": string,
"rcvd": integer
2020-03-27 07:31:08 -07:00
"size": string
2019-11-11 18:30:46 -08:00
}
]
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:
2019-12-17 10:09:19 -08:00
List of dictionaries. Raw or processed structured data.
2019-11-11 18:30:46 -08:00