Skip to content

Commit

Permalink
minor fix to iw-scan to parse more fields
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyjonbrazil committed Nov 26, 2024
1 parent 3665892 commit a2b5d41
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 7 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
jc changelog

20241124 v1.25.4
20241125 v1.25.4
- Add `ipconfig` command parser (`ipconfig` for Windows)
- Add `pacman` command parser
- Add `wg show` command parser
Expand All @@ -11,6 +11,7 @@ jc changelog
- Fix `bluetoothctl` parser when extra attributes like `manufacturer` and `version` exist
- Fix `df` parser to correctly output binary vs. decimal size outputs
- Fix `ip-address` parser for Python 3.13 changes to IPv4 mapped IPv6 addresses
- Fix `iw-scan` parser to output more fields (still beta quality)
- Fix `mount` parser for cases where there are spaces in the filesystem name
- Fix `netstat` parser for cases where there are spaces in the program name
- Fix `pkg-index-deb`, `apt-cache-show`, and `rpm-qi` parsers to correctly convert contiguous packages with the same name
Expand Down
2 changes: 1 addition & 1 deletion docs/parsers/iw_scan.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,4 @@ Compatibility: linux

Source: [`jc/parsers/iw_scan.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/iw_scan.py)

Version 0.7 by Kelly Brazil ([email protected])
Version 0.75 by Kelly Brazil ([email protected])
7 changes: 5 additions & 2 deletions jc/parsers/iw_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@

class info():
"""Provides parser metadata (version, author, etc.)"""
version = '0.7'
version = '0.75'
description = '`iw dev [device] scan` command parser'
author = 'Kelly Brazil'
author_email = '[email protected]'
Expand Down Expand Up @@ -298,6 +298,7 @@ def parse(data, raw=False, quiet=False):

raw_output = []
section = {}
header = ''

if jc.utils.has_data(data):

Expand All @@ -323,7 +324,9 @@ def parse(data, raw=False, quiet=False):
split_line[0] = split_line[0].lower().replace('*', '').replace('(', '')\
.replace(')', '').replace(',', '').replace('-', '_')\
.strip().replace(' ', '_')
section[split_line[0]] = split_line[1].strip()
if split_line[1] == '':
header = split_line[0] + '_'
section[header + split_line[0]] = split_line[1].strip()

continue

Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/centos-7.7/iw-scan0.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"bssid": "00:19:a9:cd:c6:80", "interface": "wlan0", "freq": 2412, "capability": "ESS ShortPreamble ShortSlotTime (0x0421)", "ssid": "Cisco1240", "supported_rates": [1.0, 2.0, 5.5, 6.0, 9.0, 11.0, 12.0, 18.0], "erp": "<no flags>", "extended_supported_rates": [24.0, 36.0, 48.0, 54.0], "wmm": "Parameter version 1", "be": "CW 15-1023, AIFSN 3", "bk": "CW 15-1023, AIFSN 7", "vi": "CW 7-15, AIFSN 2, TXOP 3008 usec", "vo": "CW 3-7, AIFSN 2, TXOP 1504 usec", "tsf_usec": 2984923701, "beacon_interval_tus": 100, "signal_dbm": -45.0, "last_seen_ms": 429, "selected_rates": [1.0, 2.0, 5.5, 11.0], "ds_parameter_set_channel": 1}, {"bssid": "d0:d0:fd:69:ca:70", "interface": "wlan0", "freq": 2462, "capability": "ESS ShortPreamble ShortSlotTime (0x0421)", "ssid": "Cisco1250", "supported_rates": [1.0, 2.0, 5.5, 6.0, 9.0, 11.0, 12.0, 18.0], "erp": "<no flags>", "extended_supported_rates": [24.0, 36.0, 48.0, 54.0], "wmm": "Parameter version 1", "be": "CW 15-1023, AIFSN 3", "bk": "CW 15-1023, AIFSN 7", "vi": "CW 7-15, AIFSN 2, TXOP 3008 usec", "vo": "acm CW 3-7, AIFSN 2, TXOP 1504 usec", "tsf_usec": 2968648942, "beacon_interval_tus": 102, "signal_dbm": -70.0, "last_seen_ms": 328, "selected_rates": [1.0, 2.0, 5.5, 11.0], "ds_parameter_set_channel": 11}]
[{"bssid":"00:19:a9:cd:c6:80","interface":"wlan0","freq":2412,"capability":"ESS ShortPreamble ShortSlotTime (0x0421)","ssid":"Cisco1240","supported_rates":[1.0,2.0,5.5,6.0,9.0,11.0,12.0,18.0],"erp":"<no flags>","extended_supported_rates":[24.0,36.0,48.0,54.0],"wmm":"Parameter version 1","be":"CW 15-1023, AIFSN 3","bk":"CW 15-1023, AIFSN 7","vi":"CW 7-15, AIFSN 2, TXOP 3008 usec","vo":"CW 3-7, AIFSN 2, TXOP 1504 usec","tsf_usec":2984923701,"beacon_interval_tus":100,"signal_dbm":-45.0,"last_seen_ms":429,"selected_rates":[1.0,2.0,5.5,11.0],"ds_parameter_set_channel":1},{"bssid":"d0:d0:fd:69:ca:70","interface":"wlan0","freq":2462,"capability":"ESS ShortPreamble ShortSlotTime (0x0421)","ssid":"Cisco1250","supported_rates":[1.0,2.0,5.5,6.0,9.0,11.0,12.0,18.0],"erp":"<no flags>","extended_supported_rates":[24.0,36.0,48.0,54.0],"wmm":"Parameter version 1","be":"CW 15-1023, AIFSN 3","bk":"CW 15-1023, AIFSN 7","vi":"CW 7-15, AIFSN 2, TXOP 3008 usec","vo":"acm CW 3-7, AIFSN 2, TXOP 1504 usec","tsf_usec":2968648942,"beacon_interval_tus":102,"signal_dbm":-70.0,"last_seen_ms":328,"selected_rates":[1.0,2.0,5.5,11.0],"ds_parameter_set_channel":11}]
2 changes: 1 addition & 1 deletion tests/fixtures/centos-7.7/iw-scan1.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/fixtures/centos-7.7/iw-scan2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"bssid":"xx:xx:xx:xx:3e:41","interface":"wlan0-1","freq":2412,"capability":"ESS (0x1431)","information_elements_from_probe_response_frame_ssid":"Troubleshooting","information_elements_from_probe_response_frame_rsn":"Version: 1","information_elements_from_probe_response_frame_group_cipher":"CCMP","information_elements_from_probe_response_frame_pairwise_ciphers":"CCMP","information_elements_from_probe_response_frame_authentication_suites":"PSK","information_elements_from_probe_response_frame_capabilities":"16-PTKSA-RC 1-GTKSA-RC (0x000c)","ht_capabilities_capabilities":"0x1ef","ht_capabilities_max_amsdu_length":"3839 bytes","ht_capabilities_minimum_rx_ampdu_time_spacing":"No restriction (0x00)","ht_capabilities_ht_rx_mcs_rate_indexes_supported":"0-15","ht_operation_primary_channel":1,"ht_operation_secondary_channel_offset":"no secondary","ht_operation_sta_channel_width":"20 MHz","vht_capabilities_0x33800192_max_mpdu_length":11454,"vht_capabilities_0x33800192_supported_channel_width":"neither 160 nor 80 80","vht_rx_mcs_set_1_streams":"MCS 0-9","vht_rx_mcs_set_2_streams":"MCS 0-9","vht_rx_mcs_set_3_streams":"not supported","vht_rx_mcs_set_4_streams":"not supported","vht_rx_mcs_set_5_streams":"not supported","vht_rx_mcs_set_6_streams":"not supported","vht_rx_mcs_set_7_streams":"not supported","vht_rx_mcs_set_8_streams":"not supported","vht_rx_mcs_set_vht_rx_highest_supported":"780 Mbps","vht_tx_mcs_set_1_streams":"MCS 0-9","vht_tx_mcs_set_2_streams":"MCS 0-9","vht_tx_mcs_set_3_streams":"not supported","vht_tx_mcs_set_4_streams":"not supported","vht_tx_mcs_set_5_streams":"not supported","vht_tx_mcs_set_6_streams":"not supported","vht_tx_mcs_set_7_streams":"not supported","vht_tx_mcs_set_8_streams":"not supported","vht_tx_mcs_set_vht_tx_highest_supported":"780 Mbps","vht_tx_mcs_set_vht_extended_nss":"not supported","vht_operation_channel_width":"0 (20 or 40 MHz)","vht_operation_center_freq_segment_1":0,"vht_operation_center_freq_segment_2":0,"vht_operation_vht_basic_mcs_set":"0xfffa","he_mac_capabilities_0x010102000040_minimum_payload_size_of_128_bytes":1,"he_mac_capabilities_0x010102000040_he_phy_capabilities":"(0x06304c090c008008020c00):","he_mac_capabilities_0x010102000040_device_class":1,"he_mac_capabilities_0x010102000040_dcm_max_constellation":1,"he_mac_capabilities_0x010102000040_dcm_max_constellation_rx":1,"he_mac_capabilities_0x010102000040_beamformee_sts_<=_80mhz":3,"he_mac_capabilities_0x010102000040_max_nc":1,"he_mac_capabilities_0x010102000040_1_streams":"MCS 0-11","he_mac_capabilities_0x010102000040_2_streams":"MCS 0-11","he_mac_capabilities_0x010102000040_3_streams":"not supported","he_mac_capabilities_0x010102000040_4_streams":"not supported","he_mac_capabilities_0x010102000040_5_streams":"not supported","he_mac_capabilities_0x010102000040_6_streams":"not supported","he_mac_capabilities_0x010102000040_7_streams":"not supported","he_mac_capabilities_0x010102000040_8_streams":"not supported","tsf_usec":608162896731,"beacon_interval_tus":100,"signal_dbm":-54.0,"last_seen_ms":1410}]
109 changes: 109 additions & 0 deletions tests/fixtures/centos-7.7/iw-scan2.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
BSS xx:xx:xx:xx:3e:41(on wlan0-1)
last seen: 4206.107s [boottime]
TSF: 608162896731 usec (7d, 00:56:02)
freq: 2412
beacon interval: 100 TUs
capability: ESS (0x1431)
signal: -54.00 dBm
last seen: 1410 ms ago
Information elements from Probe Response frame:
SSID: Troubleshooting
RSN: * Version: 1
* Group cipher: CCMP
* Pairwise ciphers: CCMP
* Authentication suites: PSK
* Capabilities: 16-PTKSA-RC 1-GTKSA-RC (0x000c)
HT capabilities:
Capabilities: 0x1ef
RX LDPC
HT20/HT40
SM Power Save disabled
RX HT20 SGI
RX HT40 SGI
TX STBC
RX STBC 1-stream
Max AMSDU length: 3839 bytes
No DSSS/CCK HT40
Maximum RX AMPDU length 65535 bytes (exponent: 0x003)
Minimum RX AMPDU time spacing: No restriction (0x00)
HT RX MCS rate indexes supported: 0-15
HT TX MCS rate indexes are undefined
HT operation:
* primary channel: 1
* secondary channel offset: no secondary
* STA channel width: 20 MHz
VHT capabilities:
VHT Capabilities (0x33800192):
Max MPDU length: 11454
Supported Channel Width: neither 160 nor 80 80
RX LDPC
TX STBC
RX antenna pattern consistency
TX antenna pattern consistency
VHT RX MCS set:
1 streams: MCS 0-9
2 streams: MCS 0-9
3 streams: not supported
4 streams: not supported
5 streams: not supported
6 streams: not supported
7 streams: not supported
8 streams: not supported
VHT RX highest supported: 780 Mbps
VHT TX MCS set:
1 streams: MCS 0-9
2 streams: MCS 0-9
3 streams: not supported
4 streams: not supported
5 streams: not supported
6 streams: not supported
7 streams: not supported
8 streams: not supported
VHT TX highest supported: 780 Mbps
VHT extended NSS: not supported
VHT operation:
* channel width: 0 (20 or 40 MHz)
* center freq segment 1: 0
* center freq segment 2: 0
* VHT basic MCS set: 0xfffa
HE capabilities:
HE MAC Capabilities (0x010102000040):
HTC HE Supported
Minimum Payload size of 128 bytes: 1
OM Control
A-MSDU in A-MPDU
HE PHY Capabilities: (0x06304c090c008008020c00):
HE40/2.4GHz
HE40/HE80/5GHz
Device Class: 1
LDPC Coding in Payload
STBC Tx <= 80MHz
STBC Rx <= 80MHz
Full Bandwidth UL MU-MIMO
DCM Max Constellation: 1
DCM Max Constellation Rx: 1
Beamformee STS <= 80Mhz: 3
PPE Threshold Present
Max NC: 1
20MHz in 40MHz HE PPDU 2.4GHz
TX 1024-QAM
RX 1024-QAM
HE RX MCS and NSS set <= 80 MHz
1 streams: MCS 0-11
2 streams: MCS 0-11
3 streams: not supported
4 streams: not supported
5 streams: not supported
6 streams: not supported
7 streams: not supported
8 streams: not supported
HE TX MCS and NSS set <= 80 MHz
1 streams: MCS 0-11
2 streams: MCS 0-11
3 streams: not supported
4 streams: not supported
5 streams: not supported
6 streams: not supported
7 streams: not supported
8 streams: not supported
PPE Threshold 0x19 0x1c 0xc7 0x71
13 changes: 12 additions & 1 deletion tests/test_iw_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,26 @@


class MyTests(unittest.TestCase):

# input
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/iw-scan0.out'), 'r', encoding='utf-8') as f:
centos_7_7_iw_scan0 = f.read()

with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/iw-scan1.out'), 'r', encoding='utf-8') as f:
centos_7_7_iw_scan1 = f.read()

with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/iw-scan2.out'), 'r', encoding='utf-8') as f:
centos_7_7_iw_scan2 = f.read()

# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/iw-scan0.json'), 'r', encoding='utf-8') as f:
centos_7_7_iw_scan0_json = json.loads(f.read())

with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/iw-scan1.json'), 'r', encoding='utf-8') as f:
centos_7_7_iw_scan1_json = json.loads(f.read())

with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/iw-scan2.json'), 'r', encoding='utf-8') as f:
centos_7_7_iw_scan2_json = json.loads(f.read())


def test_iw_scan_nodata(self):
"""
Expand All @@ -41,6 +46,12 @@ def test_iw_scan1_centos_7_7(self):
"""
self.assertEqual(jc.parsers.iw_scan.parse(self.centos_7_7_iw_scan1, quiet=True), self.centos_7_7_iw_scan1_json)

def test_iw_scan2_centos_7_7(self):
"""
Test 'iw_scan' on Centos 7.7
"""
self.assertEqual(jc.parsers.iw_scan.parse(self.centos_7_7_iw_scan2, quiet=True), self.centos_7_7_iw_scan2_json)


if __name__ == '__main__':
unittest.main()

0 comments on commit a2b5d41

Please sign in to comment.