diff --git a/jc/parsers/dig.py b/jc/parsers/dig.py index 904361da..0ac8ba8d 100644 --- a/jc/parsers/dig.py +++ b/jc/parsers/dig.py @@ -4,34 +4,149 @@ Usage: Specify --dig as the first argument if the piped input is coming from dig Examples: -$ dig www.cnn.com - -; <<>> DiG 9.11.4-P2-RedHat-9.11.4-9.P2.el7 <<>> www.cnn.com -;; global options: +cmd -;; Got answer: -;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 11061 -;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 1 - -;; OPT PSEUDOSECTION: -; EDNS: version: 0, flags:; MBZ: 0x0005, udp: 4096 -;; QUESTION SECTION: -;www.cnn.com. IN A - -;; ANSWER SECTION: -www.cnn.com. 5 IN CNAME turner-tls.map.fastly.net. -turner-tls.map.fastly.net. 5 IN A 151.101.129.67 -turner-tls.map.fastly.net. 5 IN A 151.101.1.67 -turner-tls.map.fastly.net. 5 IN A 151.101.193.67 -turner-tls.map.fastly.net. 5 IN A 151.101.65.67 - -;; Query time: 43 msec -;; SERVER: 192.168.71.2#53(192.168.71.2) -;; WHEN: Wed Oct 30 00:43:32 PDT 2019 -;; MSG SIZE rcvd: 143 - +$ dig cnn.com www.cnn.com @205.251.194.64 | jc --dig -p +[ + { + "id": "28182", + "opcode": "QUERY", + "status": "NOERROR", + "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": "5", + "data": "151.101.193.67" + }, + { + "name": "cnn.com.", + "class": "IN", + "type": "A", + "ttl": "5", + "data": "151.101.1.67" + }, + { + "name": "cnn.com.", + "class": "IN", + "type": "A", + "ttl": "5", + "data": "151.101.129.67" + }, + { + "name": "cnn.com.", + "class": "IN", + "type": "A", + "ttl": "5", + "data": "151.101.65.67" + } + ], + "query_time": "45 msec", + "server": "192.168.71.2#53(192.168.71.2)", + "when": "Wed Oct 30 03:11:21 PDT 2019", + "rcvd": "100" + }, + { + "id": "23264", + "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": "33 msec", + "server": "205.251.194.64#53(205.251.194.64)", + "when": "Wed Oct 30 03:11:21 PDT 2019", + "rcvd": "212" + } +] +$ dig -x 1.1.1.1 | jc --dig -p +[ + { + "id": "27526", + "opcode": "QUERY", + "status": "NOERROR", + "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": "5", + "data": "one.one.one.one." + } + ], + "query_time": "34 msec", + "server": "192.168.71.2#53(192.168.71.2)", + "when": "Wed Oct 30 03:13:48 PDT 2019", + "rcvd": "98" + } +] """ -import pprint def parse_header(header): @@ -199,6 +314,4 @@ def parse(data): output.append(output_entry) clean_output = list(filter(None, output)) - pprint.pprint(clean_output) - exit() - # return clean_output + return clean_output