diff --git a/tests/fixtures/centos-7.7/netstat-i.json b/tests/fixtures/centos-7.7/netstat-i.json new file mode 100644 index 00000000..0308b011 --- /dev/null +++ b/tests/fixtures/centos-7.7/netstat-i.json @@ -0,0 +1 @@ +[{"iface": "docker0", "mtu": 1500, "rx_ok": 0, "rx_err": 0, "rx_drp": 0, "rx_ovr": 0, "tx_ok": 0, "tx_err": 0, "tx_drp": 0, "tx_ovr": 0, "flg": "BMU", "kind": "interface"}, {"iface": "ens33", "mtu": 1500, "rx_ok": 476, "rx_err": 0, "rx_drp": 0, "rx_ovr": 0, "tx_ok": 312, "tx_err": 0, "tx_drp": 0, "tx_ovr": 0, "flg": "BMRU", "kind": "interface"}, {"iface": "lo", "mtu": 65536, "rx_ok": 0, "rx_err": 0, "rx_drp": 0, "rx_ovr": 0, "tx_ok": 0, "tx_err": 0, "tx_drp": 0, "tx_ovr": 0, "flg": "LRU", "kind": "interface"}] diff --git a/tests/fixtures/osx-10.14.6/netstat-i.json b/tests/fixtures/osx-10.14.6/netstat-i.json new file mode 100644 index 00000000..c152e526 --- /dev/null +++ b/tests/fixtures/osx-10.14.6/netstat-i.json @@ -0,0 +1 @@ +[{"iface": "lo0", "mtu": 16384, "network": "", "address": null, "ipkts": 1580150, "ierrs": 0, "opkts": 1580150, "oerrs": 0, "coll": 0, "kind": "interface"}, {"iface": "lo0", "mtu": 16384, "network": "127", "address": "localhost", "ipkts": 1580150, "ierrs": null, "opkts": 1580150, "oerrs": null, "coll": null, "kind": "interface"}, {"iface": "lo0", "mtu": 16384, "network": "localhost", "address": "::1", "ipkts": 1580150, "ierrs": null, "opkts": 1580150, "oerrs": null, "coll": null, "kind": "interface"}, {"iface": "lo0", "mtu": 16384, "network": "fe80::1%lo0", "address": "fe80:1::1", "ipkts": 1580150, "ierrs": null, "opkts": 1580150, "oerrs": null, "coll": null, "kind": "interface"}, {"iface": "gif0*", "mtu": 1280, "network": "", "address": null, "ipkts": 0, "ierrs": 0, "opkts": 0, "oerrs": 0, "coll": 0, "kind": "interface"}, {"iface": "stf0*", "mtu": 1280, "network": "", "address": null, "ipkts": 0, "ierrs": 0, "opkts": 0, "oerrs": 0, "coll": 0, "kind": "interface"}, {"iface": "VHC12", "mtu": 0, "network": "", "address": null, "ipkts": 0, "ierrs": 0, "opkts": 0, "oerrs": 0, "coll": 0, "kind": "interface"}, {"iface": "XHC1*", "mtu": 0, "network": "", "address": null, "ipkts": 0, "ierrs": 0, "opkts": 0, "oerrs": 0, "coll": 0, "kind": "interface"}, {"iface": "XHC0*", "mtu": 0, "network": "", "address": null, "ipkts": 0, "ierrs": 0, "opkts": 0, "oerrs": 0, "coll": 0, "kind": "interface"}, {"iface": "XHC20", "mtu": 0, "network": "", "address": null, "ipkts": 0, "ierrs": 0, "opkts": 0, "oerrs": 0, "coll": 0, "kind": "interface"}, {"iface": "en5", "mtu": 1500, "network": "", "address": "ac:de:48:00:11:22", "ipkts": 140215, "ierrs": 0, "opkts": 137522, "oerrs": 721, "coll": 0, "kind": "interface"}, {"iface": "en5", "mtu": 1500, "network": "fe80::aede:", "address": "fe80:8::aede:48ff", "ipkts": 140215, "ierrs": null, "opkts": 137522, "oerrs": null, "coll": null, "kind": "interface"}, {"iface": "ap1*", "mtu": 1500, "network": "", "address": "a6:83:e7:2d:62:8f", "ipkts": 0, "ierrs": 0, "opkts": 0, "oerrs": 0, "coll": 0, "kind": "interface"}, {"iface": "en0", "mtu": 1500, "network": "", "address": "a4:83:e7:2d:62:8f", "ipkts": 23300545, "ierrs": 0, "opkts": 26448755, "oerrs": 464, "coll": 0, "kind": "interface"}, {"iface": "en0", "mtu": 1500, "network": "kbrazil-mac", "address": "fe80:a::cf9:ca6f:", "ipkts": 23300545, "ierrs": null, "opkts": 26448755, "oerrs": null, "coll": null, "kind": "interface"}, {"iface": "en0", "mtu": 1500, "network": "192.168.1", "address": "kbrazil-mac.att", "ipkts": 23300545, "ierrs": null, "opkts": 26448755, "oerrs": null, "coll": null, "kind": "interface"}, {"iface": "en0", "mtu": 1500, "network": "kbrazil-mac", "address": "2600:1700:bab0:d4", "ipkts": 23300545, "ierrs": null, "opkts": 26448755, "oerrs": null, "coll": null, "kind": "interface"}, {"iface": "en0", "mtu": 1500, "network": "kbrazil-mac", "address": "2600:1700:bab0:d4", "ipkts": 23300545, "ierrs": null, "opkts": 26448755, "oerrs": null, "coll": null, "kind": "interface"}, {"iface": "en0", "mtu": 1500, "network": "kbrazil-mac", "address": "2600:1700:bab0:d4", "ipkts": 23300545, "ierrs": null, "opkts": 26448755, "oerrs": null, "coll": null, "kind": "interface"}, {"iface": "en0", "mtu": 1500, "network": "kbrazil-mac", "address": "2600:1700:bab0:d4", "ipkts": 23300545, "ierrs": null, "opkts": 26448755, "oerrs": null, "coll": null, "kind": "interface"}, {"iface": "en0", "mtu": 1500, "network": "kbrazil-mac", "address": "2600:1700:bab0:d4", "ipkts": 23300545, "ierrs": null, "opkts": 26448755, "oerrs": null, "coll": null, "kind": "interface"}, {"iface": "en0", "mtu": 1500, "network": "kbrazil-mac", "address": "2600:1700:bab0:d4", "ipkts": 23300545, "ierrs": null, "opkts": 26448755, "oerrs": null, "coll": null, "kind": "interface"}, {"iface": "p2p0", "mtu": 2304, "network": "", "address": "06:83:e7:2d:62:8f", "ipkts": 0, "ierrs": 0, "opkts": 0, "oerrs": 0, "coll": 0, "kind": "interface"}, {"iface": "awdl0", "mtu": 1484, "network": "", "address": "b6:1f:b7:57:a5:4f", "ipkts": 0, "ierrs": 0, "opkts": 5097, "oerrs": 0, "coll": 0, "kind": "interface"}, {"iface": "awdl0", "mtu": 1484, "network": "fe80::b41f:", "address": "fe80:c::b41f:b7ff", "ipkts": 0, "ierrs": null, "opkts": 5097, "oerrs": null, "coll": null, "kind": "interface"}, {"iface": "en1", "mtu": 1500, "network": "", "address": "ea:00:fd:08:57:01", "ipkts": 0, "ierrs": 0, "opkts": 0, "oerrs": 0, "coll": 0, "kind": "interface"}, {"iface": "en2", "mtu": 1500, "network": "", "address": "ea:00:fd:08:57:00", "ipkts": 0, "ierrs": 0, "opkts": 0, "oerrs": 0, "coll": 0, "kind": "interface"}, {"iface": "en3", "mtu": 1500, "network": "", "address": "ea:00:fd:08:57:05", "ipkts": 0, "ierrs": 0, "opkts": 0, "oerrs": 0, "coll": 0, "kind": "interface"}, {"iface": "en4", "mtu": 1500, "network": "", "address": "ea:00:fd:08:57:04", "ipkts": 0, "ierrs": 0, "opkts": 0, "oerrs": 0, "coll": 0, "kind": "interface"}, {"iface": "bridg", "mtu": 1500, "network": "", "address": "ea:00:fd:08:57:01", "ipkts": 0, "ierrs": 0, "opkts": 0, "oerrs": 0, "coll": 0, "kind": "interface"}, {"iface": "utun0", "mtu": 2000, "network": "", "address": null, "ipkts": 0, "ierrs": 0, "opkts": 159, "oerrs": 0, "coll": 0, "kind": "interface"}, {"iface": "utun0", "mtu": 2000, "network": "kbrazil-mac", "address": "fe80:12::30fe:52f", "ipkts": 0, "ierrs": null, "opkts": 159, "oerrs": null, "coll": null, "kind": "interface"}, {"iface": "utun1", "mtu": 1380, "network": "", "address": null, "ipkts": 0, "ierrs": 0, "opkts": 2, "oerrs": 0, "coll": 0, "kind": "interface"}, {"iface": "utun1", "mtu": 1380, "network": "kbrazil-mac", "address": "fe80:15::aaf6:178", "ipkts": 0, "ierrs": null, "opkts": 2, "oerrs": null, "coll": null, "kind": "interface"}, {"iface": "utun2", "mtu": 1380, "network": "", "address": null, "ipkts": 0, "ierrs": 0, "opkts": 2, "oerrs": 0, "coll": 0, "kind": "interface"}, {"iface": "utun2", "mtu": 1380, "network": "kbrazil-mac", "address": "fe80:16::ce02:efd", "ipkts": 0, "ierrs": null, "opkts": 2, "oerrs": null, "coll": null, "kind": "interface"}, {"iface": "utun3", "mtu": 1380, "network": "", "address": null, "ipkts": 0, "ierrs": 0, "opkts": 2, "oerrs": 0, "coll": 0, "kind": "interface"}, {"iface": "utun3", "mtu": 1380, "network": "kbrazil-mac", "address": "fe80:17::1188:a03", "ipkts": 0, "ierrs": null, "opkts": 2, "oerrs": null, "coll": null, "kind": "interface"}, {"iface": "vmnet", "mtu": 1500, "network": "", "address": "00:50:56:c0:00:01", "ipkts": 0, "ierrs": 0, "opkts": 0, "oerrs": 0, "coll": 0, "kind": "interface"}, {"iface": "vmnet", "mtu": 1500, "network": "192.168.101", "address": "192.168.101.1", "ipkts": 0, "ierrs": null, "opkts": 0, "oerrs": null, "coll": null, "kind": "interface"}, {"iface": "vmnet", "mtu": 1500, "network": "", "address": "00:50:56:c0:00:08", "ipkts": 1853, "ierrs": 0, "opkts": 0, "oerrs": 0, "coll": 0, "kind": "interface"}, {"iface": "vmnet", "mtu": 1500, "network": "192.168.71", "address": "192.168.71.1", "ipkts": 1853, "ierrs": null, "opkts": 0, "oerrs": null, "coll": null, "kind": "interface"}] diff --git a/tests/fixtures/ubuntu-18.04/netstat-i.json b/tests/fixtures/ubuntu-18.04/netstat-i.json new file mode 100644 index 00000000..d006c394 --- /dev/null +++ b/tests/fixtures/ubuntu-18.04/netstat-i.json @@ -0,0 +1 @@ +[{"iface": "ens33", "mtu": 1500, "rx_ok": 245, "rx_err": 0, "rx_drp": 0, "rx_ovr": 0, "tx_ok": 197, "tx_err": 0, "tx_drp": 0, "tx_ovr": 0, "flg": "BMRU", "kind": "interface"}, {"iface": "lo", "mtu": 65536, "rx_ok": 94, "rx_err": 0, "rx_drp": 0, "rx_ovr": 0, "tx_ok": 94, "tx_err": 0, "tx_drp": 0, "tx_ovr": 0, "flg": "LRU", "kind": "interface"}] diff --git a/tests/fixtures/ubuntu-18.04/netstat-i.out b/tests/fixtures/ubuntu-18.04/netstat-i.out new file mode 100644 index 00000000..dd692429 --- /dev/null +++ b/tests/fixtures/ubuntu-18.04/netstat-i.out @@ -0,0 +1,4 @@ +Kernel Interface table +Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg +ens33 1500 245 0 0 0 197 0 0 0 BMRU +lo 65536 94 0 0 0 94 0 0 0 LRU diff --git a/tests/test_netstat.py b/tests/test_netstat.py index 82b201df..05f7124c 100644 --- a/tests/test_netstat.py +++ b/tests/test_netstat.py @@ -81,6 +81,16 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/netstat-rnl.out'), 'r', encoding='utf-8') as f: self.osx_14_6_netstat_rnl = f.read() + # netstat -i + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-i.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_netstat_i = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-i.out'), 'r', encoding='utf-8') as f: + self.ubuntu_18_4_netstat_i = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/netstat-i.out'), 'r', encoding='utf-8') as f: + self.osx_14_6_netstat_i = f.read() + # # output # @@ -153,6 +163,16 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/netstat-rnl.json'), 'r', encoding='utf-8') as f: self.osx_14_6_netstat_rnl_json = json.loads(f.read()) + # netstat -i + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-i.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_netstat_i_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-i.json'), 'r', encoding='utf-8') as f: + self.ubuntu_18_4_netstat_i_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/netstat-i.json'), 'r', encoding='utf-8') as f: + self.osx_14_6_netstat_i_json = json.loads(f.read()) + def test_netstat_centos_7_7(self): """ Test 'netstat' on Centos 7.7 @@ -285,6 +305,24 @@ class MyTests(unittest.TestCase): """ self.assertEqual(jc.parsers.netstat.parse(self.osx_14_6_netstat_rnl, quiet=True), self.osx_14_6_netstat_rnl_json) + def test_netstat_i_centos_7_7(self): + """ + Test 'netstat -i' on Centos 7.7 + """ + self.assertEqual(jc.parsers.netstat.parse(self.centos_7_7_netstat_i, quiet=True), self.centos_7_7_netstat_i_json) + + def test_netstat_i_ubuntu_18_4(self): + """ + Test 'netstat -i' on Ubuntu 18.4 + """ + self.assertEqual(jc.parsers.netstat.parse(self.ubuntu_18_4_netstat_i, quiet=True), self.ubuntu_18_4_netstat_i_json) + + def test_netstat_i_osx_16_4(self): + """ + Test 'netstat -i' on OSX 16.4 + """ + self.assertEqual(jc.parsers.netstat.parse(self.osx_14_6_netstat_i, quiet=True), self.osx_14_6_netstat_i_json) + if __name__ == '__main__': unittest.main()