Create a gist now

Instantly share code, notes, and snippets.

@buhman /wpa_cli
Last active Nov 19, 2017

What would you like to do?
wpa_cli example; it might be worth mention that you can tab-complete all wpa_supplicant commands
[zack@leto ~]$ sudo tee << EOF /etc/wpa_supplicant.conf > /dev/null
ctrl_interface=/run/wpa_supplicant
EOF
[zack@leto ~]$ sudo wpa_supplicant -iwlp1s0 -Dnl80211 -c/etc/wpa_supplicant.conf -B
Successfully initialized wpa_supplicant
[zack@leto ~]$ sudo 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]
> set update_config 1
OK
> save_config
OK
> quit
[zack@leto ~]$ cat /etc/wpa_supplicant.conf
ctrl_interface=/run/wpa_supplicant
update_config=1
network={
ssid="buhman"
psk="world domination"
}
[zack@leto ~]$ dhcpcd wlp1s0
dhcpcd[20226]: version 6.1.0 starting
dhcpcd[20226]: wlp1s0: soliciting an IPv6 router
dhcpcd[20226]: wlp1s0: soliciting a DHCP lease
dhcpcd[20226]: wlp1s0: offered 192.168.1.100 from 192.168.1.1
dhcpcd[20226]: wlp1s0: leased 192.168.1.100 for 86400 seconds
dhcpcd[20226]: wlp1s0: adding host route to 192.168.1.100 via 127.0.0.1
dhcpcd[20226]: wlp1s0: adding route to 192.168.1.0/24
dhcpcd[20226]: wlp1s0: adding default route via 192.168.1.1
dhcpcd[20226]: forked to background, child pid 20319
[zack@leto ~]$ # now say we're going off to... starbucks or something and we want to connect to it; simple
[zack@leto ~]$ sudo 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 [CURRENT]
1 starbucks any [DISABLED]
> enable_network 1
OK
> select_network 1
<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
[zack@leto ~]$ # all done!

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."

@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"?

Beia

@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.

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.

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