Skip to content

Instantly share code, notes, and snippets.

@buhman
Last active July 18, 2024 07:46
Show Gist options
  • Save buhman/7162560 to your computer and use it in GitHub Desktop.
Save buhman/7162560 to your computer and use it in GitHub Desktop.
all wpa_cli ommands can be tab-completed
localhost ~ # cat <<EOF> /etc/wpa_supplicant.conf
ctrl_interface=DIR=/run/wpa_supplicant GROUP=wheel
update_config=1
EOF
localhost ~ # wpa_supplicant -iwlp1s0 -Dnl80211 -c/etc/wpa_supplicant.conf -B
Successfully initialized wpa_supplicant
localhost ~ # wpa_cli
wpa_cli v2.0
Copyright (c) 2004-2012, Jouni Malinen <j@w1.fi> and contributors
This software may be distributed under the terms of the BSD license.
See README for more details.
Selected interface 'wlp1s0'
Interactive mode
> status
wpa_state=DISCONNECTED
p2p_device_address=00:15:6d:85:5b:1f
address=00:15:6d:85:5b:1f
> scan
OK
<3>CTRL-EVENT-SCAN-RESULTS
> scan_results
bssid / frequency / signal level / flags / ssid
f8:1a:67:78:4b:af 2462 -34 [WPA2-PSK-CCMP][ESS] buhman
> add_network
0
> list_network
network id / ssid / bssid / flags
0 any [DISABLED]
> set_network 0 ssid "buhman"
OK
> set_network 0 psk "world domination"
OK
> list_network
network id / ssid / bssid / flags
0 buhman any [DISABLED]
> enable_network 0
OK
<3>CTRL-EVENT-SCAN-RESULTS
<3>WPS-AP-AVAILABLE
<3>SME: Trying to authenticate with f8:1a:67:78:4b:af (SSID='buhman' freq=2462 MHz)
<3>Trying to associate with f8:1a:67:78:4b:af (SSID='buhman' freq=2462 MHz)
<3>Associated with f8:1a:67:78:4b:af
<3>WPA: Key negotiation completed with f8:1a:67:78:4b:af [PTK=CCMP GTK=CCMP]
<3>CTRL-EVENT-CONNECTED - Connection to f8:1a:67:78:4b:af completed [id=0 id_str=]
> status
bssid=f8:1a:67:78:4b:af
ssid=buhman
id=0
mode=station
pairwise_cipher=CCMP
group_cipher=CCMP
key_mgmt=WPA2-PSK
wpa_state=COMPLETED
p2p_device_address=00:15:6d:85:5b:1f
address=00:15:6d:85:5b:1f
> list_networks
network id / ssid / bssid / flags
0 buhman any [CURRENT]
> save_config
OK
> quit
localhost ~ # cat /etc/wpa_supplicant.conf
ctrl_interface=/run/wpa_supplicant
update_config=1
network={
ssid="buhman"
psk="world domination"
}
localhost ~ # wpa_cli
wpa_cli v2.0
Copyright (c) 2004-2012, Jouni Malinen <j@w1.fi> and contributors
This software may be distributed under the terms of the BSD license.
See README for more details.
Selected interface 'wlp1s0'
Interactive mode
> add_network
1
> set_network 1 ssid "starbucks"
OK
> set_network 1 key_mgmt NONE
OK
> list_networks
network id / ssid / bssid / flags
0 buhman any
1 starbucks any [DISABLED]
> enable_network 1
OK
<3>CTRL-EVENT-SCAN-RESULTS
<3>WPS-AP-AVAILABLE
<3>SME: Trying to authenticate with 3e:20:1d:c6:0e:d2 (SSID='starbucks' freq=2412 MHz)
<3>Trying to associate with 3e:20:1d:c6:0e:d2 (SSID='starbucks' freq=2412 MHz)
<3>Associated with 3e:20:1d:c6:0e:d2
<3>CTRL-EVENT-CONNECTED - Connection to 3e:20:1d:c6:0e:d2 completed [id=0 id_str=]
> save_config
OK
> quit
@RoundSparrow
Copy link

Do you have a wpa_cli and p2p_cli that work (compiled) for Android 5.0 and later? Binaries that work on 4.4 return: "only position independent executables (PIE) are supported."

@modulitos
Copy link

@buhman I have been using wpa_cli for a while, and it's working great! But now I have hundreds of networks, and I have a hard time finding the network number associated with the ssid that I want to connect to. Is there any way that I can search for a network, or select a network, based on its ssid?

For example, imagine the following:

> list_networks
network id / ssid / bssid / flags
0       jumjee  any     [DISABLED]
1       TG      any     [DISABLED]
2       AlphaBeta       any     [DISABLED]
3       the wand        any     [DISABLED]
4       DRINK ALL CITY COFFEE   any     [DISABLED]
5       StellarPizza    any     [DISABLED]
6       HUB     any     [DISABLED]
<many more networks...>
125     Tullys Free Wi-Fi       any     [DISABLED]
> select_network 75
OK

where network 75 is a network called "foo" (where the ssid is "foo"). It's very hard to find the network number, especially when list_networks seems to limit its output to 125 networks. Is there a command, or script, that I can run that will do something like select_network foo? Or even something like find_network_by_ssid foo and will return "75"?

@mahdilahit
Copy link

Beia

@Earnestly
Copy link

@Lukeswart That 125 limit sounds awful, have you reported these issues to hostap yet? That surely sounds like a bug, and moreover I agree that the requirement for associated numbers instead of SSID seems like very poor UI design.

@amarchandole
Copy link

My wireless interface does not get assigned an IPv6 link local address (which I am guessing should never be the case). I get to see the correct link-local once in a while but it vanishes after a reboot or network restart. I am using wpa_supplicant with nl80211 driver. I can connect two devices using p2p (wifi direct) and I wish to be able to ping one from another using the link-local IPv6 address.

@dsh2
Copy link

dsh2 commented Dec 31, 2020

@modulitos To find the number of a given ssid, you can grep for it in non-interactive mode like so wpa_cli list_networks | grep ssid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment