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

    1. Wi-Fi (wifi) commands:
    2. help or -h
    3. Print this help text.
    4. get-country-code
    5. Gets country code as a two-letter string
    6. set-wifi-enabled enabled|disabled
    7. Enables/disables Wifi on this device.
    8. set-scan-always-available enabled|disabled
    9. Sets whether scanning should be available even when wifi is off.
    10. list-scan-results
    11. Lists the latest scan results
    12. start-scan
    13. Start a new scan
    14. list-networks
    15. Lists the saved networks
    16. connect-network <ssid> open|owe|wpa2|wpa3 [<passphrase>] [-m] [-d] [-b <bssid>]
    17. Connect to a network with provided params and add to saved networks list
    18. <ssid> - SSID of the network
    19. open|owe|wpa2|wpa3 - Security type of the network.
    20. - Use 'open' or 'owe' for networks with no passphrase
    21. - 'open' - Open networks (Most prevalent)
    22. - 'owe' - Enhanced open networks
    23. - Use 'wpa2' or 'wpa3' for networks with passphrase
    24. - 'wpa2' - WPA-2 PSK networks (Most prevalent)
    25. - 'wpa3' - WPA-3 PSK networks
    26. -m - Mark the network metered.
    27. -d - Mark the network autojoin disabled.
    28. -b <bssid> - Set specific BSSID.
    29. add-network <ssid> open|owe|wpa2|wpa3 [<passphrase>] [-m] [-d] [-b <bssid>]
    30. Add/update saved network with provided params
    31. <ssid> - SSID of the network
    32. open|owe|wpa2|wpa3 - Security type of the network.
    33. - Use 'open' or 'owe' for networks with no passphrase
    34. - 'open' - Open networks (Most prevalent)
    35. - 'owe' - Enhanced open networks
    36. - Use 'wpa2' or 'wpa3' for networks with passphrase
    37. - 'wpa2' - WPA-2 PSK networks (Most prevalent)
    38. - 'wpa3' - WPA-3 PSK networks
    39. -m - Mark the network metered.
    40. -d - Mark the network autojoin disabled.
    41. -b <bssid> - Set specific BSSID.
    42. forget-network <networkId>
    43. Remove the network mentioned by <networkId>
    44. - Use list-networks to retrieve <networkId> for the network
    45. status
    46. Current wifi status
    47. set-verbose-logging enabled|disabled
    48. Set the verbose logging enabled or disabled
    49. add-suggestion <ssid> open|owe|wpa2|wpa3 [<passphrase>] [-u] [-m] [-s] [-d][-b <bssid>]
    50. Add a network suggestion with provided params
    51. Use 'network-suggestions-set-user-approved com.android.shell yes' to approve suggestions added via shell (Needs root access)
    52. <ssid> - SSID of the network
    53. open|owe|wpa2|wpa3 - Security type of the network.
    54. - Use 'open' or 'owe' for networks with no passphrase
    55. - 'open' - Open networks (Most prevalent)
    56. - 'owe' - Enhanced open networks
    57. - Use 'wpa2' or 'wpa3' for networks with passphrase
    58. - 'wpa2' - WPA-2 PSK networks (Most prevalent)
    59. - 'wpa3' - WPA-3 PSK networks
    60. -u - Mark the suggestion untrusted.
    61. -m - Mark the suggestion metered.
    62. -s - Share the suggestion with user.
    63. -d - Mark the suggestion autojoin disabled.
    64. -b <bssid> - Set specific BSSID.
    65. remove-suggestion <ssid>
    66. Remove a network suggestion with provided SSID of the network
    67. remove-all-suggestions
    68. Removes all suggestions added via shell
    69. list-suggestions
    70. Lists the suggested networks added via shell
    71. set-connected-score <score>
    72. Set connected wifi network score (to choose between LTE & Wifi for default route).
    73. This turns off the active connected scorer (default or external).
    74. 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.
    75. <score> - Integer score should be in the range of 0 - 60
    76. reset-connected-score
    77. Turns on the default connected scorer.
    78. Note: Will clear any external scorer set.
    79. start-softap <ssid> (open|wpa2) <passphrase> [-b 2|5|6|any]
    80. Start softap with provided params
    81. 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.
    82. - SSID of the network
    83. open|wpa2 - Security type of the network.
    84. - Use 'open' for networks with no passphrase
    85. - Use 'wpa2' for networks with passphrase
    86. -b 2|5|6|any - select the preferred band.
    87. - Use '2' to select 2.4GHz band as the preferred band
    88. - Use '5' to select 5GHz band as the preferred band
    89. - Use '6' to select 6GHz band as the preferred band
    90. - Use 'any' to indicate no band preference
    91. Note: If the band option is not provided, 2.4GHz is the preferred band.
    92. The exact channel is auto-selected by FW unless overridden by force-softap-channel command
    93. stop-softap
    94. Stop softap (hotspot)
    95. set-ipreach-disconnect enabled|disabled
    96. Sets whether CMD_IP_REACHABILITY_LOST events should trigger disconnects.
    97. get-ipreach-disconnect
    98. Gets setting of CMD_IP_REACHABILITY_LOST events triggering disconnects.
    99. set-poll-rssi-interval-msecs
    100. Sets the interval between RSSI polls to milliseconds.
    101. get-poll-rssi-interval-msecs
    102. Gets current interval between RSSI polls, in milliseconds.
    103. force-hi-perf-mode enabled|disabled
    104. Sets whether hi-perf mode is forced or left for normal operation.
    105. force-low-latency-mode enabled|disabled
    106. Sets whether low latency mode is forced or left for normal operation.
    107. network-suggestions-set-user-approved yes|no
    108. Sets whether network suggestions from the app is approved or not.
    109. network-suggestions-has-user-approved
    110. Queries whether network suggestions from the app is approved or not.
    111. imsi-protection-exemption-set-user-approved-for-carrier yes|no
    112. Sets whether Imsi protection exemption for carrier is approved or not
    113. imsi-protection-exemption-has-user-approved-for-carrier
    114. Queries whether Imsi protection exemption for carrier is approved or not
    115. imsi-protection-exemption-clear-user-approved-for-carrier
    116. Clear the user choice on Imsi protection exemption for carrier
    117. network-requests-remove-user-approved-access-points
    118. Removes all user approved network requests for the app.
    119. clear-user-disabled-networks
    120. Clears the user disabled networks list.
    121. send-link-probe
    122. Manually triggers a link probe.
    123. force-softap-channel enabled | disabled
    124. Sets whether soft AP channel is forced to MHz
    125. or left for normal operation.
    126. force-country-code enabled | disabled
    127. Sets country code to or left for normal value
    128. set-wifi-watchdog enabled|disabled
    129. Sets whether wifi watchdog should trigger recovery
    130. get-wifi-watchdog
    131. Gets setting of wifi watchdog trigger recovery.
    132. get-softap-supported-features
    133. Gets softap supported features. Will print 'wifi_softap_acs_supported'
    134. and/or 'wifi_softap_wpa3_sae_supported', each on a separate line.
    135. settings-reset
    136. Initiates wifi settings reset
    137. add-request open|owe|wpa2|wpa3 [] [-b ]
    138. Add a network request with provided params
    139. Use 'network-requests-set-user-approved android yes' to pre-approve requests added via rooted shell (Not persisted)
    140. - SSID of the network
    141. open|owe|wpa2|wpa3 - Security type of the network.
    142. - Use 'open' or 'owe' for networks with no passphrase
    143. - 'open' - Open networks (Most prevalent)
    144. - 'owe' - Enhanced open networks
    145. - Use 'wpa2' or 'wpa3' for networks with passphrase
    146. - 'wpa2' - WPA-2 PSK networks (Most prevalent)
    147. - 'wpa3' - WPA-3 PSK networks
    148. -b - Set specific BSSID.
    149. remove-request
    150. Remove a network request with provided SSID of the network
    151. remove-all-requests
    152. Removes all active requests added via shell
    153. list-requests
    154. Lists the requested networks added via shell
    155. network-requests-set-user-approved yes|no
    156. Sets whether network requests from the app is approved or not.
    157. Note: Only 1 such app can be approved from the shell at a time
    158. network-requests-has-user-approved
    159. Queries whether network requests from the app is approved or not.
    160. Note: This only returns whether the app was set via the 'network-requests-set-user-approved' shell command
    161. qca-list-ifaces
    162. Lists active STA/AP interfaces (could be bridge interfaces). Command to set bridge iface will only apply to the first internal iface
    163. qca-set-txpower
    164. Sets max txpower in dBm, and is from 'qca-list-ifaces'
    165. qca-set-ani-level []
    166. Sets ani level, and is from 'qca-list-ifaces'
    167. qca-get-thermal-info
    168. Gets thermal info, and is from 'qca-list-ifaces'
    169. qca-dump-thermal-events
    170. Dump thermal events from driver/firmware after boot
    171. qca-set-congestion-report [ [interval]]
    172. Sets congestion report, and is AP iface from 'qca-list-ifaces'
    173. qca-dump-congestion-events
    174. Dump congestion events from driver/firmware after boot

  • 相关阅读:
    【力扣刷题】整数拆分(动态规划)
    基于粒子群算法优化BP神经网络的PID控制算法(Matlab代码实现)
    【无标题】
    Android log 系统
    C#-懒汉单例创建
    Android平台GB28181设备接入端对接编码前后音视频源类型浅析
    华为机试真题 C++ 实现【工号不够用了怎么办?】
    Prometheus安装与配置
    LeetCode 389. 找不同
    【英杰送书第三期】Spring 解决依赖版本不一致报错 | 文末送书
  • 原文地址:https://blog.csdn.net/BOJUE01/article/details/136684847