cmd wifi
命令完整的说明说下。
console:/ # cmd wifi
Wi-Fi (wifi) commands:help or -hPrint this help text.get-country-codeGets country code as a two-letter stringset-wifi-enabled enabled|disabledEnables/disables Wifi on this device.set-scan-always-available enabled|disabledSets whether scanning should be available even when wifi is off.list-scan-resultsLists the latest scan resultsstart-scanStart a new scanlist-networksLists the saved networksforget-network <networkId>Remove the network mentioned by <networkId>- Use list-networks to retrieve <networkId> for the networkstatusCurrent wifi statusset-verbose-logging enabled|disabled Set the verbose logging enabled or disabledis-verbose-loggingCheck whether verbose logging enabled or disabledstart-restricting-auto-join-to-subscription-id subIdtemporarily disable all wifi networks except merged carrier networks with the given subIdstop-restricting-auto-join-to-subscription-idUndo the effects of start-restricting-auto-join-to-subscription-idadd-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 paramsUse 'network-suggestions-set-user-approved com.android.shell yes' to approve suggestions added via shell (Needs root access)<ssid> - SSID of the networkopen|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 setremove-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-suggestionsRemoves all suggestions added via shelllist-suggestionsLists the suggested networks added via shellset-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-channelsRemoves all cell channels set in set-coex-cell-channels and returns to listening on actual device reported cell channelsget-coex-cell-channelsPrints 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 - 60reset-connected-scoreTurns 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 paramsNote 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 networkopen|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 + 5GNote: 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-softapStop softap (hotspot)pmksa-flush <networkId>- Flush the local PMKSA cache associated with the network id. Use list-networks to retrieve <networkId> for the networkreload-resourcesReset 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 millisecondslaunch-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 inputlaunch-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 millisecondsquery-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 okinterface-priority-interactive-mode enable|disable|defaultEnable 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|disabledSets whether CMD_IP_REACHABILITY_LOST events should trigger disconnects.get-ipreach-disconnectGets 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 networkopen|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 networkadd-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 networkopen|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 networkset-poll-rssi-interval-msecs <int>Sets the interval between RSSI polls to <int> milliseconds.get-poll-rssi-interval-msecsGets current interval between RSSI polls, in milliseconds.force-hi-perf-mode enabled|disabledSets whether hi-perf mode is forced or left for normal operation.force-low-latency-mode enabled|disabledSets whether low latency mode is forced or left for normal operation.network-suggestions-set-user-approved <package name> yes|noSets 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|noSets whether Imsi protection exemption for carrier is approved or notimsi-protection-exemption-has-user-approved-for-carrier <carrier id>Queries whether Imsi protection exemption for carrier is approved or notimsi-protection-exemption-clear-user-approved-for-carrier <carrier id>Clear the user choice on Imsi protection exemption for carriernetwork-requests-remove-user-approved-access-points <package name>Removes all user approved network requests for the app.clear-user-disabled-networksClears the user disabled networks list.send-link-probeManually triggers a link probe.force-softap-band enabled <int> | disabledForces soft AP band to 2|5|6force-softap-channel enabled <int> | disabledSets whether soft AP channel is forced to <int> MHzor left for normal operation.force-country-code enabled <two-letter code> | disabled Sets country code to <two-letter code> or left for normal valueor '00' for forcing to world mode country codeset-wifi-watchdog enabled|disabledSets whether wifi watchdog should trigger recoveryget-wifi-watchdogGets setting of wifi watchdog trigger recovery.get-softap-supported-featuresGets 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-resetInitiates wifi settings resetadd-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 paramsUse '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 presentopen|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 networkremove-all-requestsRemoves all active requests added via shelllist-requestsLists the requested networks added via shellnetwork-requests-set-user-approved <package name> yes|noSets whether network requests from the app is approved or not.Note: Only 1 such app can be approved from the shell at a timenetwork-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 commandlist-all-suggestionsLists all suggested networks on this devicelist-suggestions-from-app <package name>Lists the suggested networks from the appset-emergency-callback-mode enabled|disabledSets whether Emergency Callback Mode (ECBM) is enabled.Equivalent to receiving the TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED broadcast.set-emergency-call-state enabled|disabledSets 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|noSet 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-recoveryTrigger Wi-Fi subsystem restart.start-faking-scansStart faking scan results into the framework (configured with 'add-fake-scan'), stop with 'stop-faking-scans'.stop-faking-scansStop 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 -55Example WPA3: add-fake-scan fakeWpa3 80:01:02:03:04:06 "[RSN-SAE+FT/SAE-CCMP][ESS]" 2412 -55Example Open: add-fake-scan fakeOpen 80:01:02:03:04:07 "[ESS]" 2412 -55Example OWE: add-fake-scan fakeOwe 80:01:02:03:04:08 "[RSN-OWE-CCMP]" 2412 -55Example WPA2/WPA3 transition mode: add-fake-scan fakeWpa2t3 80:01:02:03:04:09 "[WPA2-PSK-CCMP][RSN-PSK+SAE-CCMP][ESS][MFPC]" 2412 -55Example Open/OWE transition mode: add-fake-scan fakeOpenOwe 80:01:02:03:04:0A "[RSN-OWE_TRANSITION-CCMP][ESS]" 2412 -55Example 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 textreset-fake-scansResets 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|disabledSets whether Passpoint should be enabled or disabledstart-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 networkopen|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 + 5GNote: If the band option is not provided, 2.4GHz is the preferred band.stop-lohsStop local only softap (hotspot)set-multi-internet-mode 0|1|2Sets Multi Internet use case mode. 0-disabled 1-dbs 2-multi apset-pno-request <ssid> [-f <frequency>]Requests to include a non-quoted UTF-8 SSID in PNO scansclear-pno-requestClear 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, etcstart-dpp-configurator-initiator <networkId> <netRole> <enrolleeURI>Start DPP Configurator Initiator mode.netRole - 0: STA, 1: APenrolleeURI - Bootstrapping URI received from Enrolleestop-dppStop 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-resultsBSSID Frequency RSSI Age(sec) SSID Flags98: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: 0SAP 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: 0SAP 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:/ #