Android 使用adb操作WiFi相关指令

本文详细介绍了如何在Android设备上使用ADBshell命令管理WiFi,包括开启/关闭WiFi、扫描网络、连接WiFi、查看状态、操作热点等,并列举了相关命令及其参数,对于开发者和调试人员非常实用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

没有系统原生设置应用又需要调试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 <ssid> open|owe|wpa2|wpa3 [<passphrase>] [-m] [-d] [-b <bssid>]
    Connect to a network with provided params and add to saved networks list
    <ssid> - 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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值