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 <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 prevalent)
           - 'wpa3' - WPA-3 PSK networks
    -m - Mark the network metered.
    -d - Mark the network autojoin disabled.
    -b <bssid> - Set specific BSSID.
  add-network <ssid> open|owe|wpa2|wpa3 [<passphrase>] [-m] [-d] [-b <bssid>]
    Add/update saved network with provided params
    <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 prevalent)
           - 'wpa3' - WPA-3 PSK networks
    -m - Mark the network metered.
    -d - Mark the network autojoin disabled.
    -b <bssid> - Set specific BSSID.
  forget-network <networkId>
    Remove the network mentioned by <networkId>
        - Use list-networks to retrieve <networkId> for the network
  status
    Current wifi status
  set-verbose-logging enabled|disabled
    Set the verbose logging enabled or disabled
  add-suggestion <ssid> open|owe|wpa2|wpa3 [<passphrase>] [-u] [-m] [-s] [-d][-b <bssid>]
    Add a network suggestion with provided params
    Use 'network-suggestions-set-user-approved com.android.shell yes' to approve suggestions added via shell (Needs root access)
    <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 prevalent)
           - 'wpa3' - WPA-3 PSK networks
    -u - Mark the suggestion untrusted.
    -m - Mark the suggestion metered.
    -s - Share the suggestion with user.
    -d - Mark the suggestion autojoin disabled.
    -b <bssid> - Set specific BSSID.
  remove-suggestion <ssid>
    Remove a network suggestion with provided SSID of the network
  remove-all-suggestions
    Removes all suggestions added via shell
  list-suggestions
    Lists the suggested networks added via shell
  set-connected-score <score>
    Set connected wifi network score (to choose between LTE & Wifi for default route).
    This turns off the active connected scorer (default or external).
    Only works while connected to a wifi network. This score will stay in effect until you call reset-connected-score or the device disconnects from the current network.
    <score> - Integer score should be in the range of 0 - 60
  reset-connected-score
    Turns on the default connected scorer.
    Note: Will clear any external scorer set.
  start-softap <ssid> (open|wpa2) <passphrase> [-b 2|5|6|any]
    Start softap with provided params
    Note that the shell command doesn't activate internet tethering. In some devices, internet sharing is possible when Wi-Fi STA is also enabled and isassociated to another AP with internet access.
    <ssid> - SSID of the network
    open|wpa2 - Security type of the network.
        - Use 'open' for networks with no passphrase
        - Use 'wpa2' for networks with passphrase
    -b 2|5|6|any - select the preferred band.
        - Use '2' to select 2.4GHz band as the preferred band
        - Use '5' to select 5GHz band as the preferred band
        - Use '6' to select 6GHz band as the preferred band
        - Use 'any' to indicate no band preference
    Note: If the band option is not provided, 2.4GHz is the preferred band.
          The exact channel is auto-selected by FW unless overridden by force-softap-channel command
  stop-softap
    Stop softap (hotspot)
  set-ipreach-disconnect enabled|disabled
    Sets whether CMD_IP_REACHABILITY_LOST events should trigger disconnects.
  get-ipreach-disconnect
    Gets setting of CMD_IP_REACHABILITY_LOST events triggering disconnects.
  set-poll-rssi-interval-msecs <int>
    Sets the interval between RSSI polls to <int> milliseconds.
  get-poll-rssi-interval-msecs
    Gets current interval between RSSI polls, in milliseconds.
  force-hi-perf-mode enabled|disabled
    Sets whether hi-perf mode is forced or left for normal operation.
  force-low-latency-mode enabled|disabled
    Sets whether low latency mode is forced or left for normal operation.
  network-suggestions-set-user-approved <package name> yes|no
    Sets whether network suggestions from the app is approved or not.
  network-suggestions-has-user-approved <package name>
    Queries whether network suggestions from the app is approved or not.
  imsi-protection-exemption-set-user-approved-for-carrier <carrier id> yes|no
    Sets whether Imsi protection exemption for carrier is approved or not
  imsi-protection-exemption-has-user-approved-for-carrier <carrier id>
    Queries whether Imsi protection exemption for carrier is approved or not
  imsi-protection-exemption-clear-user-approved-for-carrier <carrier id>
    Clear the user choice on Imsi protection exemption for carrier
  network-requests-remove-user-approved-access-points <package name>
    Removes all user approved network requests for the app.
  clear-user-disabled-networks
    Clears the user disabled networks list.
  send-link-probe
    Manually triggers a link probe.
  force-softap-channel enabled <int> | disabled
    Sets whether soft AP channel is forced to <int> MHz
    or left for normal   operation.
  force-country-code enabled <two-letter code> | disabled
    Sets country code to <two-letter code> or left for normal value
  set-wifi-watchdog enabled|disabled
    Sets whether wifi watchdog should trigger recovery
  get-wifi-watchdog
    Gets setting of wifi watchdog trigger recovery.
  get-softap-supported-features
    Gets softap supported features. Will print 'wifi_softap_acs_supported'
    and/or 'wifi_softap_wpa3_sae_supported', each on a separate line.
  settings-reset
    Initiates wifi settings reset
  add-request <ssid> open|owe|wpa2|wpa3 [<passphrase>] [-b <bssid>]
    Add a network request with provided params
    Use 'network-requests-set-user-approved android yes' to pre-approve requests added via rooted shell (Not persisted)
    <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 prevalent)
           - 'wpa3' - WPA-3 PSK networks
    -b <bssid> - Set specific BSSID.
  remove-request <ssid>
    Remove a network request with provided SSID of the network
  remove-all-requests
    Removes all active requests added via shell
  list-requests
    Lists the requested networks added via shell
  network-requests-set-user-approved <package name> yes|no
    Sets whether network requests from the app is approved or not.
    Note: Only 1 such app can be approved from the shell at a time
  network-requests-has-user-approved <package name>
    Queries whether network requests from the app is approved or not.
    Note: This only returns whether the app was set via the 'network-requests-set-user-approved' shell command
  qca-list-ifaces
    Lists active STA/AP interfaces (could be bridge interfaces). Command to set bridge iface will only apply to the first internal iface
  qca-set-txpower <iface> <power in dBm>
    Sets max txpower in dBm, and <iface> is from 'qca-list-ifaces'
  qca-set-ani-level <iface> <auto|fixed> [<ofdmlvl>]
    Sets ani level, and <iface> is from 'qca-list-ifaces'
  qca-get-thermal-info <iface>
    Gets thermal info, and <iface> is from 'qca-list-ifaces'
  qca-dump-thermal-events
    Dump thermal events from driver/firmware after boot
  qca-set-congestion-report <iface> <enable|disable> [<threshold> [interval]]
    Sets congestion report, and <iface> is AP iface from 'qca-list-ifaces'
  qca-dump-congestion-events
    Dump congestion events from driver/firmware after boot
相关推荐
戏谑11 分钟前
Android 常用布局
android·view
马甲是掉不了一点的<.<11 小时前
本地电脑使用命令行上传文件至远程服务器
linux·scp·cmd·远程文件上传
拭心12 小时前
Google 提供的 Android 端上大模型组件:MediaPipe LLM 介绍
android
带电的小王14 小时前
WhisperKit: Android 端测试 Whisper -- Android手机(Qualcomm GPU)部署音频大模型
android·智能手机·whisper·qualcomm
梦想平凡14 小时前
PHP 微信棋牌开发全解析:高级教程
android·数据库·oracle
元争栈道15 小时前
webview和H5来实现的android短视频(短剧)音视频播放依赖控件
android·音视频
阿甘知识库16 小时前
宝塔面板跨服务器数据同步教程:双机备份零停机
android·运维·服务器·备份·同步·宝塔面板·建站
元争栈道16 小时前
webview+H5来实现的android短视频(短剧)音视频播放依赖控件资源
android·音视频
MuYe16 小时前
Android Hook - 动态加载so库
android
居居飒17 小时前
Android学习(四)-Kotlin编程语言-for循环
android·学习·kotlin