Android 使用cmd wifi命令操作wifi

53 篇文章 2 订阅
8 篇文章 0 订阅

cmd wifi 命令完整的说明说下。

console:/ # cmd wifi                                                       
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
  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
  is-verbose-logging
    Check whether verbose logging enabled or disabled
  start-restricting-auto-join-to-subscription-id subId
    temporarily disable all wifi networks except merged carrier networks with the given subId
  stop-restricting-auto-join-to-subscription-id
    Undo the effects of start-restricting-auto-join-to-subscription-id
  add-suggestion <ssid> open|owe|wpa2|wpa3 [<passphrase>] [-u] [-o] [-p] [-m]  [-s] [-d] [-b <bssid>] [-e] [-i] [-a <carrierId>] [-c <subscriptionId>]
    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.
    -o - Mark the suggestion oem paid.
    -p - Mark the suggestion oem private.
    -m - Mark the suggestion metered.
    -h - Mark the network hidden.
    -s - Share the suggestion with user.
    -d - Mark the suggestion autojoin disabled.
    -b <bssid> - Set specific BSSID.
    -r - Enable non_persistent randomization (disabled by default)
    -a - Mark the suggestion carrier merged
    -c <carrierId> - set carrier Id
    -i <subscriptionId> - set subscription Id, if -a is used, this must be set
  remove-suggestion <ssid> [-l]
    Remove a network suggestion with provided SSID of the network
    -l - Remove suggestion with lingering, if not set will disconnect immediately 
  remove-all-suggestions
    Removes all suggestions added via shell
  list-suggestions
    Lists the suggested networks added via shell
  set-coex-cell-channels [lte|nr <bandNumber 1-261> <downlinkFreqKhz or UNKNOWN: -1> <downlinkBandwidthKhz or UNKNOWN: 0> <uplinkFreqKhz or UNKNOWN: -1> <uplinkBandwidthKhz or UNKNOWN: 0>] ...
    Sets a list of zero or more cell channels to use for coex calculations. Actual device reported cell channels will be ignored until reset-coex-cell-channels is called.
  reset-coex-cell-channels
    Removes all cell channels set in set-coex-cell-channels and returns to listening on actual device reported cell channels
  get-coex-cell-channels
    Prints the cell channels being used for coex.
  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|wpa3|wpa3_transition|owe|owe_transition) <passphrase> [-b 2|5|6|any|bridged]
    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|wpa3|wpa3_transition|owe|owe_transition - Security type of the network.
        - Use 'open', 'owe', 'owe_transition' for networks with no passphrase
        - Use 'wpa2', 'wpa3', 'wpa3_transition' for networks with passphrase
    -b 2|5|6|any|bridged - 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
        - Use 'bridged' to indicate bridged AP which enables APs on both 2.4G + 5G
    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
    -x - Specifies the SSID as hex digits instead of plain text (T and above)
  stop-softap
    Stop softap (hotspot)
  pmksa-flush <networkId>
        - Flush the local PMKSA cache associated with the network id. Use list-networks to retrieve <networkId> for the network
  reload-resources
    Reset the WiFi resources cache which will cause them to be reloaded next time they are accessed. Necessary if overlays are manually modified.
  launch-dialog-simple [-t <title>] [-m <message>] [-l <url> <url_start> <url_end>] [-y <positive_button_text>] [-n <negative_button_text>] [-x <neutral_button_text>] [-c <timeout_millis>]
    Launches a simple dialog and waits up to 15 seconds to print the response.
    -t - Title
    -m - Message
    -l - URL of the message, with the start and end index inside the message
    -y - Positive Button Text
    -n - Negative Button Text
    -x - Neutral Button Text
    -c - Optional timeout in milliseconds
  launch-dialog-p2p-invitation-sent <device_name> <pin> [-i <display_id>]
    Launches a P2P Invitation Sent dialog.
    <device_name> - Name of the device the invitation was sent to
    <pin> - PIN for the invited device to input
  launch-dialog-p2p-invitation-received <device_name> [-p] [-d <pin>] [-i <display_id>] [-c <timeout_millis>]
    Launches a P2P Invitation Received dialog and waits up to 15 seconds to print the response.
    <device_name> - Name of the device sending the invitation
    -p - Show PIN input
    -d - Display PIN <pin>
    -i - Display ID
    -c - Optional timeout in milliseconds
  query-interface <uid> <package_name> STA|AP|AWARE|DIRECT [-new]
    Query whether the specified could be created for the specified UID and package name, and if so - what other interfaces would be destroyed
    -new - query for a new interfaces (otherwise an existing interface is ok
  interface-priority-interactive-mode enable|disable|default
    Enable or disable asking the user when there's an interface priority conflict, |default| implies using the device default behavior.
  set-one-shot-screen-on-delay-ms <delayMs>
    set the delay for the next screen-on connectivity scan in milliseconds.
  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.
  connect-network <ssid> open|owe|wpa2|wpa3 [<passphrase>] [-x] [-m] [-d] [-b <bssid>] [-r auto|none|persistent|non_persistent]
    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
    -x - Specifies the SSID as hex digits instead of plain text
    -m - Mark the network metered.
    -d - Mark the network autojoin disabled.
    -h - Mark the network hidden.
    -p - Mark the network private (not shared).
    -b <bssid> - Set specific BSSID.
    -r auto|none|persistent|non_persistent - MAC randomization scheme for the network
  add-network <ssid> open|owe|wpa2|wpa3 [<passphrase>] [-x] [-m] [-d] [-b <bssid>] [-r auto|none|persistent|non_persistent]
    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
    -x - Specifies the SSID as hex digits instead of plain text
    -m - Mark the network metered.
    -d - Mark the network autojoin disabled.
    -h - Mark the network hidden.
    -p - Mark the network private (not shared).
    -b <bssid> - Set specific BSSID.
    -r auto|none|persistent|non_persistent - MAC randomization scheme for the network
  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-band enabled <int> | disabled
    Forces soft AP band to 2|5|6
  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
    or '00' for forcing to world mode country code
  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',
    and/or 'wifi_softap_bridged_ap_supported',
    and/or 'wifi_softap_bridged_ap_with_sta_supported',
    each on a separate line.
  settings-reset
    Initiates wifi settings reset
  add-request [-g] [-i] [-n] [-s] <ssid> open|owe|wpa2|wpa3 [<passphrase>] [-b <bssid>] [-d <band=2|5|6|60>]
    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)
    -g - Marks the following SSID as a glob pattern
    <ssid> - SSID of the network, or glob pattern if -g is present
    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.
    -i Set internet capability.
    -d Specify the band of access point: 2, 5, 6, or 60
    -s No SSID provided, to be chosen by network selection.
    -n - Prevent auto-selection of BSSID and force it to be null so that the request matches all BSSIDs.
  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
  list-all-suggestions
    Lists all suggested networks on this device
  list-suggestions-from-app <package name>
    Lists the suggested networks from the app
  set-emergency-callback-mode enabled|disabled
    Sets whether Emergency Callback Mode (ECBM) is enabled.
    Equivalent to receiving the TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED broadcast.
  set-emergency-call-state enabled|disabled
    Sets whether we are in the middle of an emergency call.
Equivalent to receiving the TelephonyManager.ACTION_EMERGENCY_CALL_STATE_CHANGED broadcast.
  network-suggestions-set-as-carrier-provider <packageName> yes|no
    Set the <packageName> work as carrier provider or not.
  is-network-suggestions-set-as-carrier-provider <packageName>
    Queries whether the <packageName> is working as carrier provider or not.
  remove-app-from-suggestion_database <packageName>
    Remove <packageName> from the suggestion database, all suggestions and user approval will be deleted, it is the same as uninstalling this app.
  trigger-recovery
    Trigger Wi-Fi subsystem restart.
  start-faking-scans
    Start faking scan results into the framework (configured with 'add-fake-scan'), stop with 'stop-faking-scans'.
  stop-faking-scans
    Stop faking scan results - started with 'start-faking-scans'.
  add-fake-scan [-x] <ssid> <bssid> <capabilities> <frequency> <dbm>
    Add a fake scan result to be used when enabled via `start-faking-scans'.
    Example WPA2: add-fake-scan fakeWpa2 80:01:02:03:04:05 "[WPA2-PSK-CCMP][RSN-PSK-CCMP][ESS]" 2412 -55
    Example WPA3: add-fake-scan fakeWpa3 80:01:02:03:04:06 "[RSN-SAE+FT/SAE-CCMP][ESS]" 2412 -55
    Example Open: add-fake-scan fakeOpen 80:01:02:03:04:07 "[ESS]" 2412 -55
    Example OWE: add-fake-scan fakeOwe 80:01:02:03:04:08 "[RSN-OWE-CCMP]" 2412 -55
    Example WPA2/WPA3 transition mode: add-fake-scan fakeWpa2t3 80:01:02:03:04:09 "[WPA2-PSK-CCMP][RSN-PSK+SAE-CCMP][ESS][MFPC]" 2412 -55
    Example Open/OWE transition mode: add-fake-scan fakeOpenOwe 80:01:02:03:04:0A "[RSN-OWE_TRANSITION-CCMP][ESS]" 2412 -55
    Example Passpoint: add-fake-scan fakePasspoint 80:01:02:03:04:0B "[WPA2-EAP/SHA1-CCMP][RSN-EAP/SHA1-CCMP][ESS][MFPR][MFPC][PASSPOINT]" 2412 -55
    -x - Specifies the SSID as hex digits instead of plain text
  reset-fake-scans
    Resets all fake scan results added by 'add-fake-scan'.
  enable-scanning enabled|disabled [-h]
    Sets whether all scanning should be enabled or disabled
    -h - Enable scanning for hidden networks.
  set-passpoint-enabled enabled|disabled
    Sets whether Passpoint should be enabled or disabled
  start-lohs <ssid> (open|wpa2|wpa3|wpa3_transition|owe|owe_transition) <passphrase> [-b 2|5|6|any]
    Start local only softap (hotspot) with provided params
    <ssid> - SSID of the network
    open|wpa2|wpa3|wpa3_transition|owe|owe_transition - Security type of the network.
        - Use 'open', 'owe', 'owe_transition' for networks with no passphrase
        - Use 'wpa2', 'wpa3', 'wpa3_transition' for networks with passphrase
    -b 2|5|6|any|bridged - 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
        - Use 'bridged' to indicate bridged AP which enables APs on both 2.4G + 5G
    Note: If the band option is not provided, 2.4GHz is the preferred band.
  stop-lohs
    Stop local only softap (hotspot)
  set-multi-internet-mode 0|1|2
    Sets Multi Internet use case mode. 0-disabled 1-dbs 2-multi ap
  set-pno-request <ssid> [-f <frequency>]
    Requests to include a non-quoted UTF-8 SSID in PNO scans
  clear-pno-request
    Clear the PNO scan request.
  start-dpp-enrollee-responder [-i <info>] [-c <curve>]
    Start DPP Enrollee responder mode.
    -i - Device Info to be used in DPP Bootstrapping URI
    -c - Cryptography Curve integer 1:p256v1, 2:s384r1, etc
  start-dpp-configurator-initiator <networkId> <netRole> <enrolleeURI>
    Start DPP Configurator Initiator mode.
    netRole - 0: STA, 1: AP
    enrolleeURI - Bootstrapping URI received from Enrollee
  stop-dpp
    Stop DPP session.

255|console:/ # 

打开wifi

cmd wifi set-wifi-enabled enabled

关闭wifi

cmd wifi set-wifi-enabled disabled

查看wifi状态

cmd wifi status

可以看到wifi的状态

  • 已关闭:
Wifi is disabled
Wifi scanning is always available
  • 已打开,未连接
Wifi is enabled
Wifi scanning is always available
==== ClientModeManager instance: ConcreteClientModeManager{id=8163428 iface=wlan0 role=ROLE_CLIENT_PRIMARY} ====
Wifi is not connected
  • 已打开并连接到网络
Wifi is enabled
Wifi scanning is always available
==== ClientModeManager instance: ConcreteClientModeManager{id=8163428 iface=wlan0 role=ROLE_CLIENT_PRIMARY} ====
Wifi is connected to "Project2"

扫描wifi网络

cmd wifi start-scan

获取扫描结果

cmd wifi list-scan-results

结果示例:

console:/ # cmd wifi list-scan-results
    BSSID              Frequency      RSSI           Age(sec)     SSID                                 Flags
  98:97:cc:50:f6:bf       5240        -90              4.404    NW-DQA-FYH_5G1                    [WPA2-PSK-CCMP][RSN-PSK-CCMP][WPA-PSK-CCMP][ESS]
  54:75:95:ff:f2:ec       5805        -89              4.404    WCS-DQA6-ZR-5G                    [ESS]
  54:75:95:ff:f2:ea       2412        -69              4.403    WCS-DQA6-ZR                       [WPA-PSK-CCMP][WPA2-PSK-CCMP][RSN-PSK-CCMP][ESS]
  a8:15:4d:3f:01:22       2472        -72              4.403    znrj3z                            [WPA-PSK-TKIP+CCMP][WPA2-PSK-TKIP+CCMP][RSN-PSK-TKIP+CCMP][ESS][WPS]
  50:eb:f6:ad:f5:80       2412        -77              4.403    Cswsl_2.4G                        [RSN-SAE-CCMP][ESS]
  80:ea:07:d8:c8:2f       2462        -49              4.404    AI                                [WPA-PSK-CCMP][WPA2-PSK-CCMP][RSN-PSK-CCMP][ESS]
  98:97:cc:50:f6:bd       2462        -70              4.403    NW-DQA-FYH                        [WPA2-PSK-CCMP][RSN-PSK-CCMP][WPA-PSK-CCMP][ESS]
  50:eb:f6:ad:f5:84       5220        -91              4.404    Cswsl_5G                          [RSN-SAE-CCMP][ESS]
  50:64:2b:79:6d:64       2437        -70              4.404    HYZY28                            [WPA-PSK-TKIP+CCMP][WPA2-PSK-TKIP+CCMP][RSN-PSK-TKIP+CCMP][ESS][WPS]
  b8:3a:08:95:a9:05       5765        -55              4.403    Project2                          [WPA-PSK-CCMP][WPA2-PSK-CCMP][RSN-PSK-CCMP][ESS][WPS]

SSID 就是wifi名称。

连接wifi

使用密码 12345678 连接 名称为 Project2 、wpa2 类型的 wifi , 密码正确才能连接上噢 😄

cmd wifi connect-network Project2 wpa2 12345678

怎么知道 wifi 是 wpa2 还是 wpa3 类型的? 从wifi扫描结果里看~

查看已保存的网络

cmd wifi list-networks

操作示例:

console:/ # cmd wifi list-networks
Network Id      SSID                         Security type
1            Project2                         wpa2-psk
1            Project2                         wpa3-sae^
console:/

忘记网络

cmd wifi forget-network <networkId>

<networkId> 通过 查看已保存的网络 得到。

操作示例:

console:/ # cmd wifi forget-network 1                                          
Forget successful

开启/关闭wifi热点

开启 wpa2 类型、名称为 hotpot11 、密码是 12345678 的 wifi热点

cmd wifi start-softap hotpot11 wpa2 12345678

操作示例:

console:/ # cmd wifi start-softap hotpot11 wpa2 12345678
onStateChanged with state: 11 failure reason: 0
 SAP is disabled
onConnectedClientsOrInfoChanged, infos: {}, clients: {}, isBridged: false
onCapabilityChanged SupportedFeatures=106 MaximumSupportedClientNumber=16 SupportedChannelListIn24g[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] SupportedChannelListIn5g[] SupportedChannelListIn6g[] SupportedChannelListIn60g[] mCountryCodeFromDriverCN
onStateChanged with state: 12 failure reason: 0
onStateChanged with state: 13 failure reason: 0
 SAP is enabled successfully
onConnectedClientsOrInfoChanged, infos: {}, clients: {}, isBridged: false
onConnectedClientsOrInfoChanged, infos: {wlan0=SoftApInfo{bandwidth= 2, frequency= 2447,bssid=98:03:cf:74:9c:1c, wifiStandard= 4, mApInstanceIdentifier= wlan0, mIdleShutdownTimeoutMillis= 600000}}, clients: {wlan0=[]}, isBridged: false

关闭wifi热点

cmd wifi stop-softap

操作示例:

console:/ # cmd wifi stop-softap
Soft AP stopped successfully

打开/关闭 自动开启wifi

cmd wifi set-scan-always-available enabled|disabled

操作示例:

console:/ # cmd wifi status
Wifi is enabled
Wifi scanning is always available
==== ClientModeManager instance: ConcreteClientModeManager{id=8163428 iface=wlan0 role=ROLE_CLIENT_PRIMARY} ====
Wifi is not connected
console:/ # 
console:/ # cmd wifi set-scan-always-available disabled
console:/ #  cmd wifi status
Wifi is enabled
Wifi scanning is only available when wifi is enabled
==== ClientModeManager instance: ConcreteClientModeManager{id=8163428 iface=wlan0 role=ROLE_CLIENT_PRIMARY} ====
Wifi is not connected
console:/ #
  • 13
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值