3

On Linux, iw and iwlist provide a wealth of information when they scan for available WiFi networks. I would say it's too much information. 2,308 lines is a lot for a human to parse. Granted, I'm in a busy apartment building, but all the more reason the verbose output is actually a hindrance for me.

$ sudo iw dev wlp8s0 scan | wc -l
2308

I would prefer a far simpler output. A relatively brief table showing a concise overview of nearby access points. This output would only show the sorts of fields (SSID, signal strength, encryption type) one might expect from a GUI WiFi utility, but in the terminal.

It seems like similar users have gone before me on this same quest, and that there are varying levels of effort put into writing complicated scripts and programs to parse simpler WiFi scanning output from Linux wireless tools like iw. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14

Almost every answer I've found to this problem suggests parsing the output from tools like iw and iwlist using grep, sed, and awk in various combinations, but that doesn't seem like a great answer. Especially since iw clearly states that its output should not be scraped.

Do NOT screenscrape this tool, we don't consider its output stable.

I'd say nmcli comes pretty close to what I want, except that I think it's heavy handed to install NetworkManager just for the convenience it provides via nmcli. Also, iw and iwlist seem more ubiquitous than nmcli in my Googling.

The WiFi scanning output of ifconfig on FreeBSD looks perfect. I'm not sure if that implementation is common across all flavors of BSD, but it's the exact sort of tool I'd hope for in Linux.

30.3.4.1.1. How to Find Access Points simple, clean, output from BSD version of ifconfig for WiFi scanning

Is there a similar stock/standard tool for almost every version of Linux that scan scan for WiFi networks and list a simple output like above?

  • I've ignored the warning and used grep in connection with iw ... scan to filter out the information I'm interested in (SSID, Frequency, BSSID). It's not that difficult to write, and easily scriptable, and re-creating the FreeBSD style (if that's what you prefer) should be easy, too. – dirkt May 14 '18 at 8:43
3

Most Linux platforms ship with wpa_supplicant, which can be used standalone or by other "frameworks" like NetworkManager, and its CLI tool wpa_cli. I don't know about newer systemd methods (which tend to replace everything else...).

# wpa_cli 
wpa_cli v2.6
[...]
Selected interface 'wlan0'

Interactive mode

> scan
OK
<3>CTRL-EVENT-SCAN-STARTED 
<3>CTRL-EVENT-SCAN-RESULTS 
<3>WPS-AP-AVAILABLE 
<3>CTRL-EVENT-NETWORK-NOT-FOUND 
<3>CTRL-EVENT-SCAN-STARTED 
<3>CTRL-EVENT-SCAN-RESULTS 
<3>WPS-AP-AVAILABLE 
<3>CTRL-EVENT-NETWORK-NOT-FOUND 
> scan_results 
bssid / frequency / signal level / flags / ssid
xx:xx:xx:xx:xx:xx   2412    -39 [WPA2-PSK-CCMP][ESS]    
xx:c7:29:xx:xx:xx   2462    -56 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS]   SomeSSID
xx:e9:dd:xx:xx:xx   2412    -57 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS]   OtherSSID
xx:8e:78:xx:xx:xx   2412    -65 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS]   AthirdSSID
[...]

or non interactively:

# wpa_cli scan_results
Selected interface 'wlan0'
bssid / frequency / signal level / flags / ssid
xx:xx:xx:xx:xx:xx   2412    -40 [WPA2-PSK-CCMP][ESS]    
[...]

(just for information, this one is a hidden ssid).

  • 1
    Thanks! I think the non-interactive scenario is most interesting to me. I'm able to do something like wpa_cli scan; sleep 3; wpa_cli scan_results to get the sort of output I'd prefer. – Will Haley May 13 '18 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.