diff --git a/changelog.txt b/changelog.txt index 9cd114e1..be83b2f7 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,6 +1,9 @@ jc changelog -20200311 v1.9.1 +20200312 v1.9.2 +- Updated arp parser to fix OSX detection for some edge cases + +20200312 v1.9.1 - Updated file command parser to make filename splitting more robust 20200311 v1.9.0 diff --git a/jc/cli.py b/jc/cli.py index fc4e17b0..75573519 100644 --- a/jc/cli.py +++ b/jc/cli.py @@ -13,7 +13,7 @@ import jc.utils class info(): - version = '1.9.1' + version = '1.9.2' description = 'jc cli output JSON conversion tool' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' diff --git a/jc/parsers/arp.py b/jc/parsers/arp.py index babffcd9..8c08e861 100644 --- a/jc/parsers/arp.py +++ b/jc/parsers/arp.py @@ -91,7 +91,7 @@ import jc.parsers.universal class info(): - version = '1.1' + version = '1.2' description = 'arp command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -160,16 +160,17 @@ def parse(data, raw=False, quiet=False): cleandata.pop(-1) # detect if osx style was used - if cleandata[0].find(' ifscope ') != -1: + if cleandata[0][-1] == ']': raw_output = [] for line in cleandata: - line = line.split() - output_line = {} - output_line['name'] = line[0] - output_line['address'] = line[1].lstrip('(').rstrip(')') - output_line['hwtype'] = line[-1].lstrip('[').rstrip(']') - output_line['hwaddress'] = line[3] - output_line['iface'] = line[5] + splitline = line.split() + output_line = { + 'name': splitline[0], + 'address': splitline[1].lstrip('(').rstrip(')'), + 'hwtype': splitline[-1].lstrip('[').rstrip(']'), + 'hwaddress': splitline[3], + 'iface': splitline[5] + } raw_output.append(output_line) if raw: diff --git a/setup.py b/setup.py index 74caf283..405b5dea 100755 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ with open('README.md', 'r') as f: setuptools.setup( name='jc', - version='1.9.1', + version='1.9.2', author='Kelly Brazil', author_email='kellyjonbrazil@gmail.com', description='This tool serializes the output of popular command line tools and filetypes to structured JSON output.', diff --git a/tests/fixtures/osx-10.14.6/arp-a2.json b/tests/fixtures/osx-10.14.6/arp-a2.json new file mode 100644 index 00000000..cd4fc372 --- /dev/null +++ b/tests/fixtures/osx-10.14.6/arp-a2.json @@ -0,0 +1 @@ +[{"name": null, "address": "169.254.81.142", "hwtype": "ethernet", "hwaddress": "60:93:17:3a:28:fc", "iface": "en0"}, {"name": "my-iphone.attlocal.net", "address": "192.168.1.64", "hwtype": "ethernet", "hwaddress": "e0:33:8f:68:39:d6", "iface": "en0"}, {"name": "my-mbp.attlocal.net", "address": "192.168.1.72", "hwtype": "ethernet", "hwaddress": "f0:18:98:3:d7:34", "iface": "en0"}, {"name": "c6180.attlocal.net", "address": "192.168.1.74", "hwtype": "ethernet", "hwaddress": "9c:b6:54:5f:fa:7c", "iface": "en0"}, {"name": "ipad.attlocal.net", "address": "192.168.1.75", "hwtype": "ethernet", "hwaddress": "4c:56:9e:5f:c7:4c", "iface": "en0"}, {"name": "mycloudex2ultra.attlocal.net", "address": "192.168.1.80", "hwtype": "ethernet", "hwaddress": "0:90:a9:ed:f4:3f", "iface": "en0"}, {"name": "family-room-5.attlocal.net", "address": "192.168.1.88", "hwtype": "ethernet", "hwaddress": "c8:d0:84:c3:e3:2d", "iface": "en0"}, {"name": "bedroom.attlocal.net", "address": "192.168.1.89", "hwtype": "ethernet", "hwaddress": "d0:3:4b:3b:29:a5", "iface": "en0"}, {"name": "heriphone.attlocal.net", "address": "192.168.1.178", "hwtype": "ethernet", "hwaddress": "90:e1:7b:ef:1:45", "iface": "en0"}, {"name": "upstairs.attlocal.net", "address": "192.168.1.186", "hwtype": "ethernet", "hwaddress": "50:32:37:d7:e5:7b", "iface": "en0"}, {"name": "rbr50.attlocal.net", "address": "192.168.1.216", "hwtype": "ethernet", "hwaddress": "3c:37:86:25:fd:f7", "iface": "en0"}, {"name": "my-mac.attlocal.net", "address": "192.168.1.221", "hwtype": "ethernet", "hwaddress": "a4:83:e7:2e:f2:8f", "iface": "en0"}, {"name": "irobot-d41934.attlocal.net", "address": "192.168.1.242", "hwtype": "ethernet", "hwaddress": "50:14:79:f2:4f:3e", "iface": "en0"}, {"name": "rbs50.attlocal.net", "address": "192.168.1.253", "hwtype": "ethernet", "hwaddress": "3c:37:86:1f:dd:a3", "iface": "en0"}, {"name": "dsldevice.attlocal.net", "address": "192.168.1.254", "hwtype": "ethernet", "hwaddress": "fc:ae:34:f1:3f:80", "iface": "en0"}, {"name": null, "address": "192.168.1.255", "hwtype": "ethernet", "hwaddress": "ff:ff:ff:ff:ff:ff", "iface": "en0"}, {"name": null, "address": "192.168.71.255", "hwtype": "ethernet", "hwaddress": "ff:ff:ff:ff:ff:ff", "iface": "vmnet8"}, {"name": null, "address": "192.168.101.255", "hwtype": "ethernet", "hwaddress": "ff:ff:ff:ff:ff:ff", "iface": "vmnet1"}, {"name": null, "address": "224.0.0.251", "hwtype": "ethernet", "hwaddress": "1:0:5e:0:0:eb", "iface": "en0"}, {"name": null, "address": "239.255.255.250", "hwtype": "ethernet", "hwaddress": "1:0:5e:7f:ff:fe", "iface": "en0"}] diff --git a/tests/fixtures/osx-10.14.6/arp-a2.out b/tests/fixtures/osx-10.14.6/arp-a2.out new file mode 100644 index 00000000..e0b43907 --- /dev/null +++ b/tests/fixtures/osx-10.14.6/arp-a2.out @@ -0,0 +1,20 @@ +? (169.254.81.142) at 60:93:17:3a:28:fc on en0 [ethernet] +my-iphone.attlocal.net (192.168.1.64) at e0:33:8f:68:39:d6 on en0 ifscope [ethernet] +my-mbp.attlocal.net (192.168.1.72) at f0:18:98:3:d7:34 on en0 ifscope [ethernet] +c6180.attlocal.net (192.168.1.74) at 9c:b6:54:5f:fa:7c on en0 ifscope [ethernet] +ipad.attlocal.net (192.168.1.75) at 4c:56:9e:5f:c7:4c on en0 ifscope [ethernet] +mycloudex2ultra.attlocal.net (192.168.1.80) at 0:90:a9:ed:f4:3f on en0 ifscope [ethernet] +family-room-5.attlocal.net (192.168.1.88) at c8:d0:84:c3:e3:2d on en0 ifscope [ethernet] +bedroom.attlocal.net (192.168.1.89) at d0:3:4b:3b:29:a5 on en0 ifscope [ethernet] +heriphone.attlocal.net (192.168.1.178) at 90:e1:7b:ef:1:45 on en0 ifscope [ethernet] +upstairs.attlocal.net (192.168.1.186) at 50:32:37:d7:e5:7b on en0 ifscope [ethernet] +rbr50.attlocal.net (192.168.1.216) at 3c:37:86:25:fd:f7 on en0 ifscope [ethernet] +my-mac.attlocal.net (192.168.1.221) at a4:83:e7:2e:f2:8f on en0 ifscope permanent [ethernet] +irobot-d41934.attlocal.net (192.168.1.242) at 50:14:79:f2:4f:3e on en0 ifscope [ethernet] +rbs50.attlocal.net (192.168.1.253) at 3c:37:86:1f:dd:a3 on en0 ifscope [ethernet] +dsldevice.attlocal.net (192.168.1.254) at fc:ae:34:f1:3f:80 on en0 ifscope [ethernet] +? (192.168.1.255) at ff:ff:ff:ff:ff:ff on en0 ifscope [ethernet] +? (192.168.71.255) at ff:ff:ff:ff:ff:ff on vmnet8 ifscope [ethernet] +? (192.168.101.255) at ff:ff:ff:ff:ff:ff on vmnet1 ifscope [ethernet] +? (224.0.0.251) at 1:0:5e:0:0:eb on en0 ifscope permanent [ethernet] +? (239.255.255.250) at 1:0:5e:7f:ff:fe on en0 ifscope permanent [ethernet] diff --git a/tests/test_arp.py b/tests/test_arp.py index 4bd23e92..011eb267 100644 --- a/tests/test_arp.py +++ b/tests/test_arp.py @@ -34,6 +34,9 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/arp-a.out'), 'r', encoding='utf-8') as f: self.osx_10_14_6_arp_a = f.read() + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/arp-a2.out'), 'r', encoding='utf-8') as f: + self.osx_10_14_6_arp_a2 = f.read() + # output with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/arp.json'), 'r', encoding='utf-8') as f: self.centos_7_7_arp_json = json.loads(f.read()) @@ -59,6 +62,9 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/arp-a.json'), 'r', encoding='utf-8') as f: self.osx_10_14_6_arp_a_json = json.loads(f.read()) + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/arp-a2.json'), 'r', encoding='utf-8') as f: + self.osx_10_14_6_arp_a2_json = json.loads(f.read()) + def test_arp_centos_7_7(self): """ Test 'arp' on Centos 7.7 @@ -107,6 +113,12 @@ class MyTests(unittest.TestCase): """ self.assertEqual(jc.parsers.arp.parse(self.osx_10_14_6_arp_a, quiet=True), self.osx_10_14_6_arp_a_json) + def test_arp_a2_osx_10_14_6(self): + """ + Test 'arp -a' with entries with no ifscope on OSX 10.14.6 + """ + self.assertEqual(jc.parsers.arp.parse(self.osx_10_14_6_arp_a2, quiet=True), self.osx_10_14_6_arp_a2_json) + if __name__ == '__main__': unittest.main()