mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
fix for spaces in dig answer data
This commit is contained in:
@ -1,5 +1,8 @@
|
|||||||
jc changelog
|
jc changelog
|
||||||
|
|
||||||
|
20210205 v1.14.2
|
||||||
|
- Update dig parser to fix cases where there are spaces in the answer data (e.g. TXT records)
|
||||||
|
|
||||||
20210106 v1.14.1
|
20210106 v1.14.1
|
||||||
- Add iw-scan parser tested on linux (beta)
|
- Add iw-scan parser tested on linux (beta)
|
||||||
- Update date parser for Ubuntu 20.04 support
|
- Update date parser for Ubuntu 20.04 support
|
||||||
|
@ -21,7 +21,7 @@ import jc.appdirs as appdirs
|
|||||||
|
|
||||||
|
|
||||||
class info():
|
class info():
|
||||||
version = '1.14.1'
|
version = '1.14.2'
|
||||||
description = 'JSON CLI output utility'
|
description = 'JSON CLI output utility'
|
||||||
author = 'Kelly Brazil'
|
author = 'Kelly Brazil'
|
||||||
author_email = 'kellyjonbrazil@gmail.com'
|
author_email = 'kellyjonbrazil@gmail.com'
|
||||||
|
@ -333,7 +333,7 @@ import jc.utils
|
|||||||
|
|
||||||
|
|
||||||
class info():
|
class info():
|
||||||
version = '1.3'
|
version = '1.4'
|
||||||
description = 'dig command parser'
|
description = 'dig command parser'
|
||||||
author = 'Kelly Brazil'
|
author = 'Kelly Brazil'
|
||||||
author_email = 'kellyjonbrazil@gmail.com'
|
author_email = 'kellyjonbrazil@gmail.com'
|
||||||
@ -526,7 +526,11 @@ def parse_answer(answer):
|
|||||||
answer_class = answer[2]
|
answer_class = answer[2]
|
||||||
answer_type = answer[3]
|
answer_type = answer[3]
|
||||||
answer_ttl = answer[1]
|
answer_ttl = answer[1]
|
||||||
answer_data = answer[4]
|
answer_data = ' '.join(answer[4:])
|
||||||
|
|
||||||
|
# remove surrounding quotation marks from answer_data if they exist
|
||||||
|
if answer_data.startswith('"') and answer_data.endswith('"'):
|
||||||
|
answer_data = answer_data[1:-1]
|
||||||
|
|
||||||
return {'name': answer_name,
|
return {'name': answer_name,
|
||||||
'class': answer_class,
|
'class': answer_class,
|
||||||
|
2
setup.py
2
setup.py
@ -5,7 +5,7 @@ with open('README.md', 'r') as f:
|
|||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name='jc',
|
name='jc',
|
||||||
version='1.14.1',
|
version='1.14.2',
|
||||||
author='Kelly Brazil',
|
author='Kelly Brazil',
|
||||||
author_email='kellyjonbrazil@gmail.com',
|
author_email='kellyjonbrazil@gmail.com',
|
||||||
description='Converts the output of popular command-line tools and file-types to JSON.',
|
description='Converts the output of popular command-line tools and file-types to JSON.',
|
||||||
|
1
tests/fixtures/generic/dig-answer-spaces.json
vendored
Normal file
1
tests/fixtures/generic/dig-answer-spaces.json
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
[{"id": 26965, "opcode": "QUERY", "status": "NXDOMAIN", "flags": ["qr", "rd", "ra"], "query_num": 1, "answer_num": 0, "authority_num": 1, "additional_num": 1, "question": {"name": "x.y.z.w.bl.spamcop.net.", "class": "IN", "type": "TXT"}, "authority": [{"name": "bl.spamcop.net.", "class": "IN", "type": "SOA", "ttl": 0, "data": "bl.spamcop.net."}], "answer": [{"name": "x.y.z.w.bl.spamcop.net.", "class": "IN", "type": "TXT", "ttl": 2100, "data": "Blocked - see https://www.spamcop.net/bl.shtml?w.z.y.x"}], "query_time": 297, "server": "192.168.1.254#53(192.168.1.254)", "when": "Fri Feb 05 06:28:58 PST 2021", "rcvd": 104}]
|
23
tests/fixtures/generic/dig-answer-spaces.out
vendored
Normal file
23
tests/fixtures/generic/dig-answer-spaces.out
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
|
||||||
|
; <<>> DiG 9.10.6 <<>> TXT x.y.z.w.bl.spamcop.net
|
||||||
|
;; global options: +cmd
|
||||||
|
;; Got answer:
|
||||||
|
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 26965
|
||||||
|
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1
|
||||||
|
|
||||||
|
;; OPT PSEUDOSECTION:
|
||||||
|
; EDNS: version: 0, flags:; udp: 4096
|
||||||
|
;; QUESTION SECTION:
|
||||||
|
;x.y.z.w.bl.spamcop.net. IN TXT
|
||||||
|
|
||||||
|
;; AUTHORITY SECTION:
|
||||||
|
bl.spamcop.net. 0 IN SOA bl.spamcop.net. hostmaster.admin.spamcop.net. 1612535191 3600 1800 3600 0
|
||||||
|
|
||||||
|
;; ANSWER SECTION:
|
||||||
|
x.y.z.w.bl.spamcop.net. 2100 IN TXT "Blocked - see https://www.spamcop.net/bl.shtml?w.z.y.x"
|
||||||
|
|
||||||
|
;; Query time: 297 msec
|
||||||
|
;; SERVER: 192.168.1.254#53(192.168.1.254)
|
||||||
|
;; WHEN: Fri Feb 05 06:28:58 PST 2021
|
||||||
|
;; MSG SIZE rcvd: 104
|
||||||
|
|
@ -55,6 +55,9 @@ class MyTests(unittest.TestCase):
|
|||||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/dig-axfr.out'), 'r', encoding='utf-8') as f:
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/dig-axfr.out'), 'r', encoding='utf-8') as f:
|
||||||
self.osx_10_14_6_dig_axfr = f.read()
|
self.osx_10_14_6_dig_axfr = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/dig-answer-spaces.out'), 'r', encoding='utf-8') as f:
|
||||||
|
self.generic_dig_answer_spaces = f.read()
|
||||||
|
|
||||||
# output
|
# output
|
||||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/dig.json'), 'r', encoding='utf-8') as f:
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/dig.json'), 'r', encoding='utf-8') as f:
|
||||||
self.centos_7_7_dig_json = json.loads(f.read())
|
self.centos_7_7_dig_json = json.loads(f.read())
|
||||||
@ -101,6 +104,9 @@ class MyTests(unittest.TestCase):
|
|||||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/dig-axfr.json'), 'r', encoding='utf-8') as f:
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/dig-axfr.json'), 'r', encoding='utf-8') as f:
|
||||||
self.osx_10_14_6_dig_axfr_json = json.loads(f.read())
|
self.osx_10_14_6_dig_axfr_json = json.loads(f.read())
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/dig-answer-spaces.json'), 'r', encoding='utf-8') as f:
|
||||||
|
self.generic_dig_answer_spaces_json = json.loads(f.read())
|
||||||
|
|
||||||
def test_dig_nodata(self):
|
def test_dig_nodata(self):
|
||||||
"""
|
"""
|
||||||
Test 'dig' with no data
|
Test 'dig' with no data
|
||||||
@ -197,6 +203,12 @@ class MyTests(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
self.assertEqual(jc.parsers.dig.parse(self.osx_10_14_6_dig_axfr, quiet=True), self.osx_10_14_6_dig_axfr_json)
|
self.assertEqual(jc.parsers.dig.parse(self.osx_10_14_6_dig_axfr, quiet=True), self.osx_10_14_6_dig_axfr_json)
|
||||||
|
|
||||||
|
def test_dig_answer_spaces(self):
|
||||||
|
"""
|
||||||
|
Test 'dig' with spaces in the answer data (e.g. TXT responses)
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.dig.parse(self.generic_dig_answer_spaces, quiet=True), self.generic_dig_answer_spaces_json)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Reference in New Issue
Block a user