Closed pschmitt closed 3 years ago
There are some special cases one needs to be aware of when implementing this.
Some access points may not broadcast any SSID. iw then displays a null character (\0
). There may be more but I personally haven't encountered any - yet ;)
Hi @pschmitt,
I have a beta version of the iw-scan parser ready.
This parser can be tested by placing a file called iw_scan.py
under $HOME/.local/share/jc/jcparsers
with the code from here: https://github.com/kellyjonbrazil/jc/blob/dev/jc/parsers/iw_scan.py.
I have noted that this parser is 'beta' quality since I don't really have a lot of examples to test with. If you have more example output for me to test I'll put it through the paces.
This output is pretty hairy, so I sorta cheated and didn't create a schema. I did make a best-effort attempt to convert ints and floats and programmatically pull as many fields in as possible. Some fields/data will be missing - most notably multi-line fields where there are not obvious key/value pairs on each line. If there are additional fields/data that you need for your use case I can improve the parser to get more of that info like I did for the dmidecode
and sysctl
parsers.
Cheers!
Cool, thanks!
I've been testing this for the last few minutes on my laptop and on Termux. For some reason I only get a few fields (mac_address
and interface
):
sudo iw dev wlan0 scan | jc --iw_scan | jq
[
{
"mac_address": "90:5c:44:d1:34:2f",
"interface": "wlan0"
},
{
"mac_address": "92:5c:14:d1:34:2f",
"interface": "wlan0"
}
]
As a sidenote it would make sense to rename mac_address
to bssid
- given the context (ref)
Thanks for the time and effort you put into this! Let me know if I can help you debug this further.
EDIT: I found the issue. See #97
Changes merged into v1.14.1, now available on pypi.
Following up on the reddit discussion:
I recently implemented something similar in shell, specifically for the
iw dev DEVICE scan
command (whereDEVICE
is a wireless nic).iw
's output is notoriously painful to parse but that's no surprise since there's a clear warning when running the command that its output shouldn't be "screen scraped". In reality I haven't seen it change much over the years.Here's an example of what
iw dev DEVICE scan
returns:iw dev wlan0 scan
``` BSS ac:22:05:db:4d:5b(on wlan0) TSF: 212106552475 usec (2d, 10:55:06) freq: 2412 beacon interval: 100 TUs capability: ESS Privacy ShortSlotTime RadioMeasure (0x1411) signal: -57.00 dBm last seen: 3520 ms ago Information elements from Probe Response frame: SSID: Hoeheitsgebiet Supported rates: 1.0* 2.0* 5.5* 11.0* 9.0 18.0 36.0 54.0 DS Parameter set: channel 1 ERP: Barker_Preamble_Mode Extended supported rates: 6.0 12.0 24.0 48.0 Country: EU Environment: Indoor/Outdoor Channels [1 - 13] @ 20 dBm HT capabilities: Capabilities: 0x1ac HT20 SM Power Save disabled RX HT20 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: 4 usec (0x05) 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 * RIFS: 0 * HT protection: no * non-GF present: 1 * OBSS non-GF present: 0 * dual beacon: 0 * dual CTS protection: 0 * STBC beacon: 0 * L-SIG TXOP Prot: 0 * PCO active: 0 * PCO phase: 0 WPA: * Version: 1 * Group cipher: TKIP * Pairwise ciphers: TKIP CCMP * Authentication suites: PSK RSN: * Version: 1 * Group cipher: TKIP * Pairwise ciphers: TKIP CCMP * Authentication suites: PSK * Capabilities: 1-PTKSA-RC 1-GTKSA-RC (0x0000) Extended capabilities: HT Information Exchange Supported, BSS Transition BSS Load: * station count: 1 * channel utilisation: 103/255 * available admission capacity: 31250 [*32us] 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 Country: EU Environment: Indoor/Outdoor Channels [1 - 13] @ 16 dBm WPS: * Version: 1.0 * Wi-Fi Protected Setup State: 2 (Configured) * Response Type: 3 (AP) * UUID: 327fd200-1dd2-11b2-8601-8e4aa01a9d4a * Manufacturer: Ralink Technology, Corp. * Model: Ralink Wireless Access Point * Model Number: RT2860 * Serial Number: 12345678 * Primary Device Type: 6-0050f204-1 * Device name: RalinkAPS * Config methods: * RF Bands: 0x1 * Unknown TLV (0x1049, 6 bytes): 00 37 2a 00 01 20 BSS 1c:b0:44:75:42:a5(on wlan0) TSF: 212108020750 usec (2d, 10:55:08) freq: 2457 beacon interval: 100 TUs capability: ESS Privacy ShortPreamble ShortSlotTime (0x0431) signal: -70.00 dBm last seen: 2050 ms ago Information elements from Probe Response frame: SSID: o2-WLAN38 Supported rates: 9.0 18.0 36.0 54.0 1.0* 2.0 5.5 11.0 DS Parameter set: channel 10 Country: DE Environment: Indoor/Outdoor Channels [1 - 13] @ 20 dBm Power constraint: 0 dB ERP: