1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00
Files
jc/tests/test_netstat.py

526 lines
24 KiB
Python
Raw Normal View History

2019-10-29 07:55:26 -07:00
import os
2019-11-08 17:08:41 -08:00
import json
2019-10-29 07:55:26 -07:00
import unittest
import jc.parsers.netstat
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
class MyTests(unittest.TestCase):
2022-09-23 14:02:27 -07:00
#
# input
#
2020-05-22 12:44:51 -07:00
2022-09-23 14:02:27 -07:00
# netstat
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat.out'), 'r', encoding='utf-8') as f:
centos_7_7_netstat = f.read()
2019-10-29 07:55:26 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat.out'), 'r', encoding='utf-8') as f:
ubuntu_18_4_netstat = f.read()
2019-10-29 07:55:26 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-l.out'), 'r', encoding='utf-8') as f:
centos_7_7_netstat_l = f.read()
2019-10-29 08:45:11 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-l.out'), 'r', encoding='utf-8') as f:
ubuntu_18_4_netstat_l = f.read()
2019-10-29 08:45:11 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-p.out'), 'r', encoding='utf-8') as f:
centos_7_7_netstat_p = f.read()
2019-10-29 08:45:11 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-p.out'), 'r', encoding='utf-8') as f:
ubuntu_18_4_netstat_p = f.read()
2019-10-29 08:45:11 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-sudo-lnp.out'), 'r', encoding='utf-8') as f:
centos_7_7_netstat_sudo_lnp = f.read()
2019-10-29 08:45:11 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-sudo-lnp.out'), 'r', encoding='utf-8') as f:
ubuntu_18_4_netstat_sudo_lnp = f.read()
2019-10-29 08:45:11 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-sudo-lnp-space.out'), 'r', encoding='utf-8') as f:
ubuntu_18_4_netstat_sudo_lnp_space = f.read()
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-sudo-aeep.out'), 'r', encoding='utf-8') as f:
centos_7_7_netstat_sudo_aeep = f.read()
2019-11-11 15:53:42 -08:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-sudo-aeep.out'), 'r', encoding='utf-8') as f:
ubuntu_18_4_netstat_sudo_aeep = f.read()
2019-11-11 15:53:42 -08:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/fedora32/netstat.out'), 'r', encoding='utf-8') as f:
fedora32_netstat = f.read()
2020-05-09 11:41:30 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/netstat.out'), 'r', encoding='utf-8') as f:
osx_14_6_netstat = f.read()
2020-05-20 17:25:25 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/netstat-An.out'), 'r', encoding='utf-8') as f:
osx_14_6_netstat_An = f.read()
2020-05-20 17:25:25 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/netstat-Abn.out'), 'r', encoding='utf-8') as f:
osx_14_6_netstat_Abn = f.read()
2020-05-20 17:25:25 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/netstat-Aa.out'), 'r', encoding='utf-8') as f:
freebsd12_netstat_Aa = f.read()
2020-05-30 15:51:06 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/netstat-an.out'), 'r', encoding='utf-8') as f:
freebsd12_netstat_an = f.read()
2020-05-30 15:51:06 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/netstat-AanP.out'), 'r', encoding='utf-8') as f:
freebsd12_netstat_AanP = f.read()
2020-05-30 15:51:06 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/netstat-AaT.out'), 'r', encoding='utf-8') as f:
freebsd12_netstat_AaT = f.read()
2020-05-30 15:51:06 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/netstat-Aax.out'), 'r', encoding='utf-8') as f:
freebsd12_netstat_Aax = f.read()
2020-05-30 15:51:06 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/netstat-aT.out'), 'r', encoding='utf-8') as f:
freebsd12_netstat_aT = f.read()
2020-05-30 15:51:06 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/netstat-old.out'), 'r', encoding='utf-8') as f:
generic_netstat_old = f.read()
2021-11-15 12:52:43 -08:00
2023-10-13 08:52:14 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/netstat-no-state.out'), 'r', encoding='utf-8') as f:
generic_netstat_no_state = f.read()
Dev v1.23.3 (#426) * make certificate search more robust to different line endings * use license_files instead of license_file which is deprecated * version bump * parsing extra options -e, -o, -p * fix for extra opts and different field length at option -[aeop] * test integration for extra opts -e -o -p * formatting and use ast.literal_eval instead of eval * doc update * doc update * Add a parser to parse mounted encrypted veracrypt volumes (fixes #403) * update compatibility warning message * netstat windows parser * tests * Windows route parser * tests * id should be a string * add veracrypt parser and docs * formatting * doc update * lsattr parser * Update test_lsattr.py * changed keys to lowercase * changed info * support missing data for stat * doc update * doc update * doc update * ensure compatibility warning prints even with no data * improve compatibility message * add support for dig +nsid option * New parser: srt (#415) * srt parser * changed the parser to support more complex cases * doc updates * Adding certificate request parser (#416) * Adding certificate request parser * Adding the CSR type for Windows-style CSR --------- Co-authored-by: Stg22 <stephane.for.test@gmail.com> * doc update * add csr tests * Last -x (#422) * Refactored the parser * last -x support * doc update * fix for ping on linux with missing hostname * allow less strict email decoding with a warning. * doc update * use explicit ascii decode with backslashreplace * doc update * use jc warning function instead of print for warning message * last -x shutdown fix (#423) * inject quiet setting into asn1crypto library * Parse appearance and modalias lines for mouse devices (fixes #419) (#425) The bluetoothctl device parser is implemented so that it aborts the parsing process immediately returning what it has collected so far. This is because the parser should work in hydrid way to support outputs comming from bluetoothctl devices and bluetoothctl info calls. * doc update * doc update --------- Co-authored-by: gerd <gerd.augstein@gmail.com> Co-authored-by: Jake Ob <iakopap@gmail.com> Co-authored-by: Mevaser <mevaser.rotner@gmail.com> Co-authored-by: M.R <69431152+YeahItsMeAgain@users.noreply.github.com> Co-authored-by: Stg22 <46686290+Stg22@users.noreply.github.com> Co-authored-by: Stg22 <stephane.for.test@gmail.com>
2023-06-22 01:48:23 +03:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/windows/windows-10/netstat.out'), 'r', encoding='utf-8') as f:
windows_netstat = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/windows/windows-10/netstat-an.out'), 'r', encoding='utf-8') as f:
windows_netstat_an = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/windows/windows-10/netstat-aon.out'), 'r', encoding='utf-8') as f:
windows_netstat_aon = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/windows/windows-10/netstat-aonb.out'), 'r', encoding='utf-8') as f:
windows_netstat_aonb = f.read()
2022-09-23 14:02:27 -07:00
# netstat -r
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-r.out'), 'r', encoding='utf-8') as f:
centos_7_7_netstat_r = f.read()
2020-05-22 12:44:51 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-rne.out'), 'r', encoding='utf-8') as f:
centos_7_7_netstat_rne = f.read()
2020-05-22 12:44:51 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-rnee.out'), 'r', encoding='utf-8') as f:
centos_7_7_netstat_rnee = f.read()
2020-05-22 12:44:51 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-r.out'), 'r', encoding='utf-8') as f:
ubuntu_18_4_netstat_r = f.read()
2020-05-22 12:44:51 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-rne.out'), 'r', encoding='utf-8') as f:
ubuntu_18_4_netstat_rne = f.read()
2020-05-22 12:44:51 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-rnee.out'), 'r', encoding='utf-8') as f:
ubuntu_18_4_netstat_rnee = f.read()
2020-05-22 11:09:41 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/netstat-r.out'), 'r', encoding='utf-8') as f:
osx_14_6_netstat_r = f.read()
2020-05-22 11:09:41 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/netstat-rnl.out'), 'r', encoding='utf-8') as f:
osx_14_6_netstat_rnl = f.read()
2020-05-22 11:09:41 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/netstat-r.out'), 'r', encoding='utf-8') as f:
freebsd12_netstat_r = f.read()
2020-05-30 15:51:06 -07:00
2022-09-23 14:02:27 -07:00
# 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:
centos_7_7_netstat_i = f.read()
2020-05-22 15:12:10 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-i.out'), 'r', encoding='utf-8') as f:
ubuntu_18_4_netstat_i = f.read()
2020-05-22 15:12:10 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/netstat-i.out'), 'r', encoding='utf-8') as f:
osx_14_6_netstat_i = f.read()
2020-05-22 15:12:10 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/netstat-i.out'), 'r', encoding='utf-8') as f:
freebsd12_netstat_i = f.read()
2020-05-30 15:51:06 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/netstat-ib.out'), 'r', encoding='utf-8') as f:
freebsd12_netstat_ib = f.read()
2020-05-30 15:51:06 -07:00
2022-09-23 14:02:27 -07:00
#
# output
#
2020-05-22 12:44:51 -07:00
2022-09-23 14:02:27 -07:00
# netstat
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat.json'), 'r', encoding='utf-8') as f:
centos_7_7_netstat_json = json.loads(f.read())
2019-11-08 17:08:41 -08:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat.json'), 'r', encoding='utf-8') as f:
ubuntu_18_4_netstat_json = json.loads(f.read())
2019-11-08 17:08:41 -08:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-l.json'), 'r', encoding='utf-8') as f:
centos_7_7_netstat_l_json = json.loads(f.read())
2019-11-08 17:08:41 -08:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-l.json'), 'r', encoding='utf-8') as f:
ubuntu_18_4_netstat_l_json = json.loads(f.read())
2019-11-08 17:08:41 -08:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-p.json'), 'r', encoding='utf-8') as f:
centos_7_7_netstat_p_json = json.loads(f.read())
2019-11-08 17:08:41 -08:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-p.json'), 'r', encoding='utf-8') as f:
ubuntu_18_4_netstat_p_json = json.loads(f.read())
2019-11-08 17:08:41 -08:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-sudo-lnp.json'), 'r', encoding='utf-8') as f:
centos_7_7_netstat_sudo_lnp_json = json.loads(f.read())
2019-11-08 17:08:41 -08:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-sudo-lnp.json'), 'r', encoding='utf-8') as f:
ubuntu_18_4_netstat_sudo_lnp_json = json.loads(f.read())
2019-11-08 17:08:41 -08:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-sudo-lnp-space.json'), 'r', encoding='utf-8') as f:
ubuntu_18_4_netstat_sudo_lnp_space_json = json.loads(f.read())
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-sudo-aeep.json'), 'r', encoding='utf-8') as f:
centos_7_7_netstat_sudo_aeep_json = json.loads(f.read())
2019-11-11 15:53:42 -08:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-sudo-aeep.json'), 'r', encoding='utf-8') as f:
ubuntu_18_4_netstat_sudo_aeep_json = json.loads(f.read())
2019-11-11 15:53:42 -08:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/fedora32/netstat.json'), 'r', encoding='utf-8') as f:
fedora32_netstat_json = json.loads(f.read())
2020-05-09 11:41:30 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/netstat.json'), 'r', encoding='utf-8') as f:
osx_14_6_netstat_json = json.loads(f.read())
2020-05-20 17:25:25 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/netstat-An.json'), 'r', encoding='utf-8') as f:
osx_14_6_netstat_An_json = json.loads(f.read())
2020-05-20 17:25:25 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/netstat-Abn.json'), 'r', encoding='utf-8') as f:
osx_14_6_netstat_Abn_json = json.loads(f.read())
2020-05-20 17:25:25 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/netstat-Aa.json'), 'r', encoding='utf-8') as f:
freebsd12_netstat_Aa_json = json.loads(f.read())
2020-05-30 15:51:06 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/netstat-AanP.json'), 'r', encoding='utf-8') as f:
freebsd12_netstat_AanP_json = json.loads(f.read())
2020-05-30 15:51:06 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/netstat-AaT.json'), 'r', encoding='utf-8') as f:
freebsd12_netstat_AaT_json = json.loads(f.read())
2020-05-30 15:51:06 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/netstat-Aax.json'), 'r', encoding='utf-8') as f:
freebsd12_netstat_Aax_json = json.loads(f.read())
2020-05-30 15:51:06 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/netstat-aT.json'), 'r', encoding='utf-8') as f:
freebsd12_netstat_aT_json = json.loads(f.read())
2020-05-30 15:51:06 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/netstat-an.json'), 'r', encoding='utf-8') as f:
freebsd12_netstat_an_json = json.loads(f.read())
2020-05-30 15:51:06 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/netstat-old.json'), 'r', encoding='utf-8') as f:
generic_netstat_old_json = json.loads(f.read())
2021-11-15 12:52:43 -08:00
2023-10-13 08:52:14 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/netstat-no-state.json'), 'r', encoding='utf-8') as f:
generic_netstat_no_state_json = json.loads(f.read())
Dev v1.23.3 (#426) * make certificate search more robust to different line endings * use license_files instead of license_file which is deprecated * version bump * parsing extra options -e, -o, -p * fix for extra opts and different field length at option -[aeop] * test integration for extra opts -e -o -p * formatting and use ast.literal_eval instead of eval * doc update * doc update * Add a parser to parse mounted encrypted veracrypt volumes (fixes #403) * update compatibility warning message * netstat windows parser * tests * Windows route parser * tests * id should be a string * add veracrypt parser and docs * formatting * doc update * lsattr parser * Update test_lsattr.py * changed keys to lowercase * changed info * support missing data for stat * doc update * doc update * doc update * ensure compatibility warning prints even with no data * improve compatibility message * add support for dig +nsid option * New parser: srt (#415) * srt parser * changed the parser to support more complex cases * doc updates * Adding certificate request parser (#416) * Adding certificate request parser * Adding the CSR type for Windows-style CSR --------- Co-authored-by: Stg22 <stephane.for.test@gmail.com> * doc update * add csr tests * Last -x (#422) * Refactored the parser * last -x support * doc update * fix for ping on linux with missing hostname * allow less strict email decoding with a warning. * doc update * use explicit ascii decode with backslashreplace * doc update * use jc warning function instead of print for warning message * last -x shutdown fix (#423) * inject quiet setting into asn1crypto library * Parse appearance and modalias lines for mouse devices (fixes #419) (#425) The bluetoothctl device parser is implemented so that it aborts the parsing process immediately returning what it has collected so far. This is because the parser should work in hydrid way to support outputs comming from bluetoothctl devices and bluetoothctl info calls. * doc update * doc update --------- Co-authored-by: gerd <gerd.augstein@gmail.com> Co-authored-by: Jake Ob <iakopap@gmail.com> Co-authored-by: Mevaser <mevaser.rotner@gmail.com> Co-authored-by: M.R <69431152+YeahItsMeAgain@users.noreply.github.com> Co-authored-by: Stg22 <46686290+Stg22@users.noreply.github.com> Co-authored-by: Stg22 <stephane.for.test@gmail.com>
2023-06-22 01:48:23 +03:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/windows/windows-10/netstat.json'), 'r', encoding='utf-8') as f:
windows_netstat_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/windows/windows-10/netstat-an.json'), 'r', encoding='utf-8') as f:
windows_netstat_an_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/windows/windows-10/netstat-aon.json'), 'r', encoding='utf-8') as f:
windows_netstat_aon_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/windows/windows-10/netstat-aonb.json'), 'r', encoding='utf-8') as f:
windows_netstat_aonb_json = json.loads(f.read())
2022-09-23 14:02:27 -07:00
# netsat -r
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-r.json'), 'r', encoding='utf-8') as f:
centos_7_7_netstat_r_json = json.loads(f.read())
2020-05-22 12:44:51 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-rne.json'), 'r', encoding='utf-8') as f:
centos_7_7_netstat_rne_json = json.loads(f.read())
2020-05-22 12:44:51 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/netstat-rnee.json'), 'r', encoding='utf-8') as f:
centos_7_7_netstat_rnee_json = json.loads(f.read())
2020-05-22 12:44:51 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-r.json'), 'r', encoding='utf-8') as f:
ubuntu_18_4_netstat_r_json = json.loads(f.read())
2020-05-22 12:44:51 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-rne.json'), 'r', encoding='utf-8') as f:
ubuntu_18_4_netstat_rne_json = json.loads(f.read())
2020-05-22 12:44:51 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-rnee.json'), 'r', encoding='utf-8') as f:
ubuntu_18_4_netstat_rnee_json = json.loads(f.read())
2020-05-22 12:44:51 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/netstat-r.json'), 'r', encoding='utf-8') as f:
osx_14_6_netstat_r_json = json.loads(f.read())
2020-05-22 11:09:41 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/netstat-rnl.json'), 'r', encoding='utf-8') as f:
osx_14_6_netstat_rnl_json = json.loads(f.read())
2020-05-22 11:09:41 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/netstat-r.json'), 'r', encoding='utf-8') as f:
freebsd12_netstat_r_json = json.loads(f.read())
2020-05-30 15:51:06 -07:00
2022-09-23 14:02:27 -07:00
# 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:
centos_7_7_netstat_i_json = json.loads(f.read())
2020-05-22 15:12:10 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/netstat-i.json'), 'r', encoding='utf-8') as f:
ubuntu_18_4_netstat_i_json = json.loads(f.read())
2020-05-22 15:12:10 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/netstat-i.json'), 'r', encoding='utf-8') as f:
osx_14_6_netstat_i_json = json.loads(f.read())
2020-05-22 15:12:10 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/netstat-i.json'), 'r', encoding='utf-8') as f:
freebsd12_netstat_i_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/freebsd12/netstat-ib.json'), 'r', encoding='utf-8') as f:
freebsd12_netstat_ib_json = json.loads(f.read())
2020-05-30 15:51:06 -07:00
2020-06-11 17:52:03 -07:00
def test_netstat_nodata(self):
"""
Test 'netstat' with no data
"""
self.assertEqual(jc.parsers.netstat.parse('', quiet=True), [])
2019-10-29 07:55:26 -07:00
def test_netstat_centos_7_7(self):
"""
Test 'netstat' on Centos 7.7
"""
2019-11-08 17:08:41 -08:00
self.assertEqual(jc.parsers.netstat.parse(self.centos_7_7_netstat, quiet=True), self.centos_7_7_netstat_json)
2019-10-29 07:55:26 -07:00
def test_netstat_ubuntu_18_4(self):
"""
Test 'netstat' on Ubuntu 18.4
"""
2019-11-08 17:08:41 -08:00
self.assertEqual(jc.parsers.netstat.parse(self.ubuntu_18_4_netstat, quiet=True), self.ubuntu_18_4_netstat_json)
2019-10-29 07:55:26 -07:00
2019-10-29 08:45:11 -07:00
def test_netstat_l_centos_7_7(self):
"""
Test 'netstat -l' on Centos 7.7
"""
2019-11-08 17:08:41 -08:00
self.assertEqual(jc.parsers.netstat.parse(self.centos_7_7_netstat_l, quiet=True), self.centos_7_7_netstat_l_json)
2019-10-29 08:45:11 -07:00
def test_netstat_l_ubuntu_18_4(self):
"""
Test 'netstat -l' on Ubuntu 18.4
"""
2019-11-08 17:08:41 -08:00
self.assertEqual(jc.parsers.netstat.parse(self.ubuntu_18_4_netstat_l, quiet=True), self.ubuntu_18_4_netstat_l_json)
2019-10-29 08:45:11 -07:00
def test_netstat_p_centos_7_7(self):
"""
Test 'netstat -l' on Centos 7.7
"""
2019-11-08 17:08:41 -08:00
self.assertEqual(jc.parsers.netstat.parse(self.centos_7_7_netstat_p, quiet=True), self.centos_7_7_netstat_p_json)
2019-10-29 08:45:11 -07:00
def test_netstat_p_ubuntu_18_4(self):
"""
Test 'netstat -l' on Ubuntu 18.4
"""
2019-11-08 17:08:41 -08:00
self.assertEqual(jc.parsers.netstat.parse(self.ubuntu_18_4_netstat_p, quiet=True), self.ubuntu_18_4_netstat_p_json)
2019-10-29 08:45:11 -07:00
def test_netstat_sudo_lnp_centos_7_7(self):
"""
Test 'sudo netstat -lnp' on Centos 7.7
"""
2019-11-08 17:08:41 -08:00
self.assertEqual(jc.parsers.netstat.parse(self.centos_7_7_netstat_sudo_lnp, quiet=True), self.centos_7_7_netstat_sudo_lnp_json)
2019-10-29 08:45:11 -07:00
def test_netstat_sudo_lnp_ubuntu_18_4(self):
"""
Test 'sudo netstat -lnp' on Ubuntu 18.4
"""
2019-11-08 17:08:41 -08:00
self.assertEqual(jc.parsers.netstat.parse(self.ubuntu_18_4_netstat_sudo_lnp, quiet=True), self.ubuntu_18_4_netstat_sudo_lnp_json)
2019-10-29 08:45:11 -07:00
def test_netstat_sudo_lnp_ubuntu_18_4(self):
"""
Test 'sudo netstat -lnp' on Ubuntu 18.4 with a space in the process name(special case)
"""
self.assertEqual(jc.parsers.netstat.parse(self.ubuntu_18_4_netstat_sudo_lnp_space, quiet=True), self.ubuntu_18_4_netstat_sudo_lnp_space_json)
2019-11-11 15:53:42 -08:00
def test_netstat_sudo_aeep_centos_7_7(self):
"""
Test 'sudo netstat -aeep' on Centos 7.7
"""
self.assertEqual(jc.parsers.netstat.parse(self.centos_7_7_netstat_sudo_aeep, quiet=True), self.centos_7_7_netstat_sudo_aeep_json)
def test_netstat_sudo_aeep_ubuntu_18_4(self):
"""
Test 'sudo netstat -aeep' on Ubuntu 18.4
"""
self.assertEqual(jc.parsers.netstat.parse(self.ubuntu_18_4_netstat_sudo_aeep, quiet=True), self.ubuntu_18_4_netstat_sudo_aeep_json)
2020-05-09 11:41:30 -07:00
def test_netstat_fedora32(self):
"""
Test 'netstat' on Fedora32
"""
self.assertEqual(jc.parsers.netstat.parse(self.fedora32_netstat, quiet=True), self.fedora32_netstat_json)
2020-05-29 13:25:19 -07:00
def test_netstat_osx_14_6(self):
2020-05-20 17:25:25 -07:00
"""
2020-05-29 13:25:19 -07:00
Test 'netstat' on OSX 14.6
2020-05-20 17:25:25 -07:00
"""
self.assertEqual(jc.parsers.netstat.parse(self.osx_14_6_netstat, quiet=True), self.osx_14_6_netstat_json)
2020-05-29 13:25:19 -07:00
def test_netstat_An_osx_14_6(self):
2020-05-20 17:25:25 -07:00
"""
2020-05-29 13:25:19 -07:00
Test 'netstat -An' on OSX 14.6
2020-05-20 17:25:25 -07:00
"""
self.assertEqual(jc.parsers.netstat.parse(self.osx_14_6_netstat_An, quiet=True), self.osx_14_6_netstat_An_json)
2020-05-29 13:25:19 -07:00
def test_netstat_Abn_osx_14_6(self):
2020-05-20 17:25:25 -07:00
"""
2020-05-29 13:25:19 -07:00
Test 'netstat -Abn' on OSX 14.6
2020-05-20 17:25:25 -07:00
"""
self.assertEqual(jc.parsers.netstat.parse(self.osx_14_6_netstat_Abn, quiet=True), self.osx_14_6_netstat_Abn_json)
2020-05-30 15:51:06 -07:00
def test_netstat_Aa_freebsd12(self):
"""
Test 'netstat -Aa' on FreeBSD12
"""
self.assertEqual(jc.parsers.netstat.parse(self.freebsd12_netstat_Aa, quiet=True), self.freebsd12_netstat_Aa_json)
def test_netstat_AanP_freebsd12(self):
"""
Test 'netstat -AanP' on FreeBSD12
"""
self.assertEqual(jc.parsers.netstat.parse(self.freebsd12_netstat_AanP, quiet=True), self.freebsd12_netstat_AanP_json)
def test_netstat_AaT_freebsd12(self):
"""
Test 'netstat -AaT' on FreeBSD12
"""
self.assertEqual(jc.parsers.netstat.parse(self.freebsd12_netstat_AaT, quiet=True), self.freebsd12_netstat_AaT_json)
def test_netstat_Aax_freebsd12(self):
"""
Test 'netstat -Aax' on FreeBSD12
"""
self.assertEqual(jc.parsers.netstat.parse(self.freebsd12_netstat_Aax, quiet=True), self.freebsd12_netstat_Aax_json)
def test_netstat_aT_freebsd12(self):
"""
Test 'netstat -aT' on FreeBSD12
"""
self.assertEqual(jc.parsers.netstat.parse(self.freebsd12_netstat_aT, quiet=True), self.freebsd12_netstat_aT_json)
def test_netstat_an_freebsd12(self):
"""
Test 'netstat -an' on FreeBSD12
"""
self.assertEqual(jc.parsers.netstat.parse(self.freebsd12_netstat_an, quiet=True), self.freebsd12_netstat_an_json)
2021-11-15 12:52:43 -08:00
def test_netstat_old_generic(self):
"""
Test 'netstat' with older version of netstat on linux
"""
self.assertEqual(jc.parsers.netstat.parse(self.generic_netstat_old, quiet=True), self.generic_netstat_old_json)
2023-10-13 08:52:14 -07:00
def test_netstat_no_state_generic(self):
"""
Test 'netstat' with no state in network output
"""
self.assertEqual(jc.parsers.netstat.parse(self.generic_netstat_no_state, quiet=True), self.generic_netstat_no_state_json)
2020-05-22 12:44:51 -07:00
def test_netstat_r_centos_7_7(self):
"""
Test 'netstat -r' on Centos 7.7
"""
self.assertEqual(jc.parsers.netstat.parse(self.centos_7_7_netstat_r, quiet=True), self.centos_7_7_netstat_r_json)
def test_netstat_rne_centos_7_7(self):
"""
Test 'netstat -rne' on Centos 7.7
"""
self.assertEqual(jc.parsers.netstat.parse(self.centos_7_7_netstat_rne, quiet=True), self.centos_7_7_netstat_rne_json)
def test_netstat_rnee_centos_7_7(self):
"""
Test 'netstat -rnee' on Centos 7.7
"""
self.assertEqual(jc.parsers.netstat.parse(self.centos_7_7_netstat_rnee, quiet=True), self.centos_7_7_netstat_rnee_json)
def test_netstat_r_ubuntu_18_4(self):
"""
Test 'netstat -r' on Ubuntu 18.4
"""
self.assertEqual(jc.parsers.netstat.parse(self.ubuntu_18_4_netstat_r, quiet=True), self.ubuntu_18_4_netstat_r_json)
def test_netstat_rne_ubuntu_18_4(self):
"""
Test 'netstat -rne' on Ubuntu 18.4
"""
self.assertEqual(jc.parsers.netstat.parse(self.ubuntu_18_4_netstat_rne, quiet=True), self.ubuntu_18_4_netstat_rne_json)
def test_netstat_rnee_ubuntu_18_4(self):
"""
Test 'netstat -rnee' on Ubuntu 18.4
"""
self.assertEqual(jc.parsers.netstat.parse(self.ubuntu_18_4_netstat_rnee, quiet=True), self.ubuntu_18_4_netstat_rnee_json)
2020-05-29 13:25:19 -07:00
def test_netstat_r_osx_14_6(self):
2020-05-22 11:09:41 -07:00
"""
2020-05-29 13:25:19 -07:00
Test 'netstat -r' on OSX 14.6
2020-05-22 11:09:41 -07:00
"""
self.assertEqual(jc.parsers.netstat.parse(self.osx_14_6_netstat_r, quiet=True), self.osx_14_6_netstat_r_json)
2020-05-29 13:25:19 -07:00
def test_netstat_rnl_osx_14_6(self):
2020-05-22 11:09:41 -07:00
"""
2020-05-29 13:25:19 -07:00
Test 'netstat -rnl' on OSX 14.6
2020-05-22 11:09:41 -07:00
"""
self.assertEqual(jc.parsers.netstat.parse(self.osx_14_6_netstat_rnl, quiet=True), self.osx_14_6_netstat_rnl_json)
2020-05-30 15:51:06 -07:00
def test_netstat_r_freebsd12(self):
"""
Test 'netstat -r' on FreeBSD12
"""
self.assertEqual(jc.parsers.netstat.parse(self.freebsd12_netstat_r, quiet=True), self.freebsd12_netstat_r_json)
2020-05-22 15:12:10 -07:00
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)
2020-05-29 13:25:19 -07:00
def test_netstat_i_osx_14_6(self):
2020-05-22 15:12:10 -07:00
"""
2020-05-29 13:25:19 -07:00
Test 'netstat -i' on OSX 14.6
2020-05-22 15:12:10 -07:00
"""
self.assertEqual(jc.parsers.netstat.parse(self.osx_14_6_netstat_i, quiet=True), self.osx_14_6_netstat_i_json)
2020-05-30 15:51:06 -07:00
def test_netstat_i_freebsd12(self):
"""
Test 'netstat -i' on FreeBSD12
"""
self.assertEqual(jc.parsers.netstat.parse(self.freebsd12_netstat_i, quiet=True), self.freebsd12_netstat_i_json)
def test_netstat_ib_freebsd12(self):
"""
Test 'netstat -ib' on FreeBSD12
"""
self.assertEqual(jc.parsers.netstat.parse(self.freebsd12_netstat_ib, quiet=True), self.freebsd12_netstat_ib_json)
Dev v1.23.3 (#426) * make certificate search more robust to different line endings * use license_files instead of license_file which is deprecated * version bump * parsing extra options -e, -o, -p * fix for extra opts and different field length at option -[aeop] * test integration for extra opts -e -o -p * formatting and use ast.literal_eval instead of eval * doc update * doc update * Add a parser to parse mounted encrypted veracrypt volumes (fixes #403) * update compatibility warning message * netstat windows parser * tests * Windows route parser * tests * id should be a string * add veracrypt parser and docs * formatting * doc update * lsattr parser * Update test_lsattr.py * changed keys to lowercase * changed info * support missing data for stat * doc update * doc update * doc update * ensure compatibility warning prints even with no data * improve compatibility message * add support for dig +nsid option * New parser: srt (#415) * srt parser * changed the parser to support more complex cases * doc updates * Adding certificate request parser (#416) * Adding certificate request parser * Adding the CSR type for Windows-style CSR --------- Co-authored-by: Stg22 <stephane.for.test@gmail.com> * doc update * add csr tests * Last -x (#422) * Refactored the parser * last -x support * doc update * fix for ping on linux with missing hostname * allow less strict email decoding with a warning. * doc update * use explicit ascii decode with backslashreplace * doc update * use jc warning function instead of print for warning message * last -x shutdown fix (#423) * inject quiet setting into asn1crypto library * Parse appearance and modalias lines for mouse devices (fixes #419) (#425) The bluetoothctl device parser is implemented so that it aborts the parsing process immediately returning what it has collected so far. This is because the parser should work in hydrid way to support outputs comming from bluetoothctl devices and bluetoothctl info calls. * doc update * doc update --------- Co-authored-by: gerd <gerd.augstein@gmail.com> Co-authored-by: Jake Ob <iakopap@gmail.com> Co-authored-by: Mevaser <mevaser.rotner@gmail.com> Co-authored-by: M.R <69431152+YeahItsMeAgain@users.noreply.github.com> Co-authored-by: Stg22 <46686290+Stg22@users.noreply.github.com> Co-authored-by: Stg22 <stephane.for.test@gmail.com>
2023-06-22 01:48:23 +03:00
def test_netstat_windows(self):
"""
Test 'netstat' on Windows
"""
self.assertEqual(jc.parsers.netstat.parse(self.windows_netstat, quiet=True), self.windows_netstat_json)
def test_netstat_an_windows(self):
"""
Test 'netstat -an' on Windows
"""
self.assertEqual(jc.parsers.netstat.parse(self.windows_netstat_an, quiet=True), self.windows_netstat_an_json)
def test_netstat_aon_windows(self):
"""
Test 'netstat -aon' on Windows
"""
self.assertEqual(jc.parsers.netstat.parse(self.windows_netstat_aon, quiet=True), self.windows_netstat_aon_json)
def test_netstat_aonb_windows(self):
"""
Test 'netstat -aonb' on Windows
"""
self.assertEqual(jc.parsers.netstat.parse(self.windows_netstat_aonb, quiet=True), self.windows_netstat_aonb_json)
2019-10-29 07:55:26 -07:00
if __name__ == '__main__':
unittest.main()