Grayson Henry Grayson Henry - 2 months ago 32
Android Question

Connect to password protected wifi network using adb shell

I have an Android phone, and the goal is to connect the phone to a password protected wifi network.

Steps I know so far:

adb root
adb shell svc wifi enable

Ok sweet, wifi is turned on.
Now I need to connect the phone a certain wireless network that requires a password.
I am hoping I can connect using an adb shell command.

Any help?

I would rather not download programs onto the device


This is possible to achieve using wpa_cli, command line interface of wpa_supplicant:

# Enable WiFi
adb root
adb shell

# Get to wpa_cli prompt
wpa_cli -p /data/misc/wifi/sockets/ -i wlan0

# Add new WiFi network
set_network 0 auth_alg OPEN
set_network 0 key_mgmt WPA-PSK
set_network 0 ssid "network_name"
set_network 0 proto RSN
set_network 0 mode 0
set_network 0 psk "password"

# Connect to it
select_network 0
enable_network 0

# Check the status

In the above list of commands, add_command will output the index of the new network, which should be used for the subsequent commands. In this example, this index is 0.