Connecting to WiFi using adb shell Connecting to WiFi using adb shell linux linux

Connecting to WiFi using adb shell


You can add a network entry into the wpa_supplicant.conf yourself (or within your script) Essentially connect manually once, then do:

adb pull /data/misc/wifi/wpa_supplicant.conf

and integrate the network entry into your script for automation. Example simple script:

#!/bin/bash## Get this information by connecting manually once, and do#   adb pull /data/misc/wifi/wpa_supplicant.confADB_PULL="adb pull /data/misc/wifi/wpa_supplicant.conf"WIRELESS_CTRL_INTERFACE=wlan0WIRELESS_SSID=GondolinWIRELESS_KEY_MGMT="WPA-EAP IEEE8021X"WIRELESS_EAP=PEAPWIRELESS_USER=TurgonWIRELESS_PASSWORD=IdrilCelebrindaladb start-serveradb wait-for-deviceecho "adb connection....[CONNECTED]"adb rootadb wait-for-deviceadb remountadb wait-for-devicepushd /tmprm wpa_supplicant.conf 2>/dev/null # Remove any old oneadbpull_status=`$ADB_PULL 2>&1`echo -e "\nAttempting: $ADB_PULL"if [ `echo $adbpull_status | grep -wc "does not exist"` -gt 0 ]; then    echo "  wpa_supplicant.conf does not exist yet on your device yet."    echo "This means you have not used your wireless yet."    echo ""    echo "Taking our best shot at creating this file with default config.."    echo "ctrl_interface=$WIRELESS_CTRL_INTERFACE" >> wpa_supplicant.conf    echo "update_config=1" >> wpa_supplicant.conf    echo "device_type=0-00000000-0" >> wpa_supplicant.confelse    echo $adbpull_status    echo "  wpa_supplicant.conf exists!"fiecho ""echo "Add network entry for wpa_supplicant.conf.."echo "" >> wpa_supplicant.confecho "network={" >> wpa_supplicant.confecho "  ssid=\"$WIRELESS_SSID\"" >> wpa_supplicant.confecho "  key_mgmt=$WIRELESS_KEY_MGMT" >> wpa_supplicant.confecho "  eap=$WIRELESS_EAP" >> wpa_supplicant.confecho "  identity=\"$WIRELESS_USER\"" >> wpa_supplicant.confecho "  password=\"$WIRELESS_PASSWORD\"" >> wpa_supplicant.confecho "  priority=1" >> wpa_supplicant.confecho "}" >> wpa_supplicant.confecho "Pushing wpa_supplicant.conf.."adb push wpa_supplicant.conf /data/misc/wifi/wpa_supplicant.confpopd #/tmpadb shell chown system.wifi /data/misc/wifi/wpa_supplicant.confadb shell chmod 660 /data/misc/wifi/wpa_supplicant.confecho ""echo "Finished!"adb shell am start -a android.intent.action.MAIN -n com.android.settings/.Settingsecho "Please toggle wifi off/on now.. (ifconfig not sufficient, monkey this)"


Late to the party, but I came up with a way to accomplish this on a device without root.

It may not be pretty, but it works.

Basically what I propose is to create an app that joins an access point based on EXTRAS given when starting the app.The EXTRAS are then provided using the am command's -e <KEY> <VALUE> parameter.

I already build an app which does so and it's available here: https://github.com/steinwurf/adb-join-wifi

Once the app is installed, a wifi access point can be joined using the following ADB command:

adb shell am start -n com.steinwurf.adbjoinwifi/com.steinwurf.adbjoinwifi.MainActivity -e ssid [SSID] -e password_type [PASSWORD_TYPE] -e password [WIFI PASSWORD]

There's more info in the README on Github.

Hope it helps someone.


As an add-on:you can enable wifi via svc as root on the device

svc wifi enable

and disable via

svc wifi disable