From 4d4b95c995ef31eace76dddff2f1bb96b60548bf Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Sun, 28 Aug 2022 12:40:46 -0700 Subject: [PATCH] fix for linx arp -a cases where an icomplete hw address is present --- CHANGELOG | 2 ++ docs/parsers/arp.md | 2 +- tests/fixtures/centos-8/arp-a.json | 1 + tests/fixtures/centos-8/arp-a.out | 4 ++++ tests/test_arp.py | 12 ++++++++++++ 5 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/centos-8/arp-a.json create mode 100644 tests/fixtures/centos-8/arp-a.out diff --git a/CHANGELOG b/CHANGELOG index 1b0c2c21..0c4566f7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,8 @@ jc changelog xxxxxxxx v1.21.1 - Fix IP Address string parser for older python versions that don't cleanly accept decimal input format (e.g. python 3.6) +- Fix `arp -a` parser for cases where incomplete hardware addresses are found + in the arp table on linux 20220821 v1.21.0 - Add IP Address string parser diff --git a/docs/parsers/arp.md b/docs/parsers/arp.md index 59750bf3..294128c7 100644 --- a/docs/parsers/arp.md +++ b/docs/parsers/arp.md @@ -140,4 +140,4 @@ Returns: ### Parser Information Compatibility: linux, aix, freebsd, darwin -Version 1.10 by Kelly Brazil (kellyjonbrazil@gmail.com) +Version 1.11 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/tests/fixtures/centos-8/arp-a.json b/tests/fixtures/centos-8/arp-a.json new file mode 100644 index 00000000..c85f2008 --- /dev/null +++ b/tests/fixtures/centos-8/arp-a.json @@ -0,0 +1 @@ +[{"name":null,"address":"192.168.71.21","hwtype":null,"hwaddress":null,"iface":"ens33"},{"name":null,"address":"192.168.71.128","hwtype":null,"hwaddress":null,"iface":"ens33"},{"name":null,"address":"192.168.71.254","hwtype":"ether","hwaddress":"00:50:56:e2:91:0e","iface":"ens33"},{"name":null,"address":"192.168.71.226","hwtype":null,"hwaddress":null,"iface":"ens33"}] diff --git a/tests/fixtures/centos-8/arp-a.out b/tests/fixtures/centos-8/arp-a.out new file mode 100644 index 00000000..a2c47922 --- /dev/null +++ b/tests/fixtures/centos-8/arp-a.out @@ -0,0 +1,4 @@ +? (192.168.71.21) at on ens33 +? (192.168.71.128) at on ens33 +? (192.168.71.254) at 00:50:56:e2:91:0e [ether] on ens33 +? (192.168.71.226) at on ens33 diff --git a/tests/test_arp.py b/tests/test_arp.py index 0d0e6850..5ac7a6c3 100644 --- a/tests/test_arp.py +++ b/tests/test_arp.py @@ -40,6 +40,9 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/arp-a.out'), 'r', encoding='utf-8') as f: self.freebsd_arp_a = f.read() + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-8/arp-a.out'), 'r', encoding='utf-8') as f: + self.centos8_arp_a = 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()) @@ -71,6 +74,9 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/arp-a.json'), 'r', encoding='utf-8') as f: self.freebsd12_arp_a_json = json.loads(f.read()) + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-8/arp-a.json'), 'r', encoding='utf-8') as f: + self.centos8_arp_a_json = json.loads(f.read()) + def test_arp_nodata(self): """ Test 'arp' with no data @@ -137,6 +143,12 @@ class MyTests(unittest.TestCase): """ self.assertEqual(jc.parsers.arp.parse(self.freebsd_arp_a, quiet=True), self.freebsd12_arp_a_json) + def test_arp_a_centos8(self): + """ + Test 'arp -a' on CentOS 8 with incomplete hw addresses + """ + self.assertEqual(jc.parsers.arp.parse(self.centos8_arp_a, quiet=True), self.centos8_arp_a_json) + if __name__ == '__main__': unittest.main()