Android 使用adb操作WiFi相关指令
没有系统原生设置应用又需要调试WiFi功能时,可以使用如下指令来验证WiFi相关功能
最常用的就是 svc wifi enable/disable,再使用wpa_supplicant/wpa_cli来验证,但对于AP功能就没办法验证了,其实Android有组很强大的shell指令集,包含各个方便,这里只记录下平时使用的WiFi相关指令
1、adb shell cmd wifi -h
查看WiFi所有指令以及参数
2、打开关闭WLAN
adb shell cmd wifi set-wifi-enabled enabled
adb shell cmd wifi set-wifi-enabled disabled
3、扫描WiFi
adb shell cmd wifi start-scan //扫描
adb shell cmd wifi list-scan-results //查看扫描结果
4、连接WiFi
adb shell cmd wifi connect-network TP-LINK_5G_0FE1 wpa2 12345678
//TP-LINK_5G_0FE1 连接WiFi名称
//wpa2 加密方式
//12345678 密码
5、查看WiFi状态
adb shell cmd wifi status
6、打开关闭热点
adb shell cmd wifi start-softap ap_ssidxx wpa2 12345678 -b5
// ap_ssidxx 热点名称
// wpa2 加密方式
//12345678 密码
//-b5 5G频段
adb shell cmd wifi stop-softap
其他可以指令可以使用adb shell cmd wifi -h查看,如果需要连接WiFi以外的相关指令可以使用adb shell cmd -l(小写L)
Wi-Fi (wifi) commands: help or -h Print this help text. get-country-code Gets country code as a two-letter string set-wifi-enabled enabled|disabled Enables/disables Wifi on this device. set-scan-always-available enabled|disabled Sets whether scanning should be available even when wifi is off. list-scan-results Lists the latest scan results start-scan Start a new scan list-networks Lists the saved networks connect-network open|owe|wpa2|wpa3 [] [-m] [-d] [-b ] Connect to a network with provided params and add to saved networks list - SSID of the network open|owe|wpa2|wpa3 - Security type of the network. - Use 'open' or 'owe' for networks with no passphrase - 'open' - Open networks (Most prevalent) - 'owe' - Enhanced open networks - Use 'wpa2' or 'wpa3' for networks with passphrase - 'wpa2' - WPA-2 PSK networks (Most pr