Linux – How to get list of available wireless networks without being root

linuxnot-root-userwifi

I would like to get a list of all the wireless networks.

iwlist wlan0 scan | grep ESSID

This will only show me the wireless network I am currently connected to. When I run the command as root, it shows me all the available networks. If I run the command without sudo quickly after this, all the networks will show up, but after a while they are all gone except the network I am currently connected to.

Is there a way to get all the available networks when I am not root?

Best Answer

You could (or do?) probably use wpa_supplicant; using its ctrl_interface configuration key, you can allow non-root users (e.g. those with group wheel) access via wpa_cli (i.e. /sbin/wpa_cli scan_results [1])

# allow frontend (e.g., wpa_cli) to be used by all users in 'wheel' group
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=wheel

There's also a command-line switch to wpa_suppliant,

-u     Enabled  DBus  control  interface. If enabled, interface definiā€
       tions may be omitted.

giving you a DBus interface and thus another possibility for non-root access (I think NetworkManager uses this interface).

[1] Once connected, this only shows the wireless LAN you are connected to...I don't know if this is any different with NetworkManager.

Related Question