shell打开wifi命令_使用adb shell连接到WiFi

本文介绍了如何通过adb shell命令连接到指定的WiFi接入点。首先手动连接一次,然后使用adb pull获取wpa_supplicant.conf文件,将网络配置集成到脚本中实现自动化。提供了一个bash脚本示例,用于生成和推送wpa_supplicant.conf,最后通过adb shell启动设置应用,提示用户切换WiFi开关以完成连接。
摘要由CSDN通过智能技术生成

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.

解决方案

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值