使用ADB Shell连接到WiFi [英] Connecting to WiFi using adb shell

查看:2198
本文介绍了使用ADB Shell连接到WiFi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我拥有连接到特定访问点的所有详细信息.我只需要使用该访问点,所以我只需要执行此操作的命令即可.

I have all the details to connect to a particular access point. I have to use that access point only, so all I require is the command to do it.

推荐答案

您可以自己(或在脚本中)将网络条目添加到wpa_supplicant.conf中,基本上手动进行一次连接,然后执行以下操作:

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.conf
ADB_PULL="adb pull /data/misc/wifi/wpa_supplicant.conf"
WIRELESS_CTRL_INTERFACE=wlan0
WIRELESS_SSID=Gondolin
WIRELESS_KEY_MGMT="WPA-EAP IEEE8021X"
WIRELESS_EAP=PEAP
WIRELESS_USER=Turgon
WIRELESS_PASSWORD=IdrilCelebrindal

adb start-server
adb wait-for-device
echo "adb connection....[CONNECTED]"
adb root
adb wait-for-device
adb remount
adb wait-for-device

pushd /tmp
rm wpa_supplicant.conf 2>/dev/null # Remove any old one
adbpull_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.conf
else
    echo $adbpull_status
    echo "  wpa_supplicant.conf exists!"
fi

echo ""
echo "Add network entry for wpa_supplicant.conf.."
echo "" >> wpa_supplicant.conf
echo "network={" >> wpa_supplicant.conf
echo "  ssid=\"$WIRELESS_SSID\"" >> wpa_supplicant.conf
echo "  key_mgmt=$WIRELESS_KEY_MGMT" >> wpa_supplicant.conf
echo "  eap=$WIRELESS_EAP" >> wpa_supplicant.conf
echo "  identity=\"$WIRELESS_USER\"" >> wpa_supplicant.conf
echo "  password=\"$WIRELESS_PASSWORD\"" >> wpa_supplicant.conf
echo "  priority=1" >> wpa_supplicant.conf
echo "}" >> wpa_supplicant.conf
echo "Pushing wpa_supplicant.conf.."
adb push wpa_supplicant.conf /data/misc/wifi/wpa_supplicant.conf
popd #/tmp

adb shell chown system.wifi /data/misc/wifi/wpa_supplicant.conf
adb shell chmod 660 /data/misc/wifi/wpa_supplicant.conf

echo ""
echo "Finished!"
adb shell am start -a android.intent.action.MAIN -n com.android.settings/.Settings
echo "Please toggle wifi off/on now.. (ifconfig not sufficient, monkey this)"

这篇关于使用ADB Shell连接到WiFi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆