wpa_cli 操作指令使用指南

一. Wpa_supplicant 启动脚本:

      wpa_supplicant -Dnl80211 -iwlan0 -c/data/misc/wifi/wpa_supplicant.conf  -O/data/misc/wifi/sockets

二. Wpa_cli 启动:

      wpa_cli是命令行界面下的无线网连接工具,在wpa_supplicant运行的基础上,打开wpa_cli:

      wpa_cli -iwlan0 -p/data/misc/wifi/sockets

三. wpa_cli 整套指令如下:

root@:/system/bin # wpa_cli -iwlan0 -p/data/misc/wifi/sockets        

wpa_cli v2.5-devel-6.0

Copyright (c) 2004-2015, Jouni Malinen <j@w1.fi> and contributors

This software may be distributed under the terms of the BSD license.

See README for more details.

Interactive mode

> help

commands:

  status [verbose] = get current WPA/EAPOL/EAP status

  ifname = get current interface name

  ping = pings wpa_supplicant

  relog = re-open log-file (allow rolling logs)

  note <text> = add a note to wpa_supplicant debug log

  mib = get MIB variables (dot1x, dot11)

  help [command] = show usage help

  interface [ifname] = show interfaces/select interface

  level <debug level> = change debug level

  license = show full wpa_cli license

  quit = exit wpa_cli

  set = set variables (shows list of variables when run without arguments)

  dump = dump config variables

  get <name> = get information

  logon = IEEE 802.1X EAPOL state machine logon

  logoff = IEEE 802.1X EAPOL state machine logoff

  pmksa = show PMKSA cache

  pmksa_flush = flush PMKSA cache entries

  reassociate = force reassociation

  reattach = force reassociation back to the same BSS

  preauthenticate <BSSID> = force preauthentication

  identity <network id> <identity> = configure identity for an SSID

  password <network id> <password> = configure password for an SSID

  new_password <network id> <password> = change password for an SSID

  pin <network id> <pin> = configure pin for an SSID

  otp <network id> <password> = configure one-time-password for an SSID

  passphrase <network id> <passphrase> = configure private key passphrase

    for an SSID

  sim <network id> <pin> = report SIM operation result

  bssid <network id> <BSSID> = set preferred BSSID for an SSID

  blacklist <BSSID> = add a BSSID to the blacklist

  blacklist clear = clear the blacklist

  blacklist = display the blacklist

  log_level <level> [<timestamp>] = update the log level/timestamp

  log_level = display the current log level and log options

  list_networks = list configured networks

  select_network <network id> = select a network (disable others)

  enable_network <network id> = enable a network

  disable_network <network id> = disable a network

  add_network = add a network

  remove_network <network id> = remove a network

  set_network <network id> <variable> <value> = set network variables (shows

    list of variables when run without arguments)

  get_network <network id> <variable> = get network variables

  dup_network <src network id> <dst network id> <variable> = duplicate network variables

  list_creds = list configured credentials

  add_cred = add a credential

  remove_cred <cred id> = remove a credential

  set_cred <cred id> <variable> <value> = set credential variables

  get_cred <cred id> <variable> = get credential variables

  save_config = save the current configuration

  disconnect = disconnect and wait for reassociate/reconnect command before

    connecting

  reconnect = like reassociate, but only takes effect if already disconnected

  scan = request new BSS scan

  scan_results = get latest scan results

  bss <<idx> | <bssid>> = get detailed scan result info

  get_capability <eap/pairwise/group/key_mgmt/proto/auth_alg/channels/freq/modes> = get capabilities

  reconfigure = force wpa_supplicant to re-read its configuration file

  terminate = terminate wpa_supplicant

  interface_add <ifname> <confname> <driver> <ctrl_interface> <driver_param>

    <bridge_name> = adds new interface, all parameters but <ifname>

    are optional

  interface_remove <ifname> = removes the interface

  interface_list = list available interfaces

  ap_scan <value> = set ap_scan parameter

  scan_interval <value> = set scan_interval parameter (in seconds)

  bss_expire_age <value> = set BSS expiration age parameter

  bss_expire_count <value> = set BSS expiration scan count parameter

  bss_flush <value> = set BSS flush age (0 by default)

  stkstart <addr> = request STK negotiation with <addr>

  ft_ds <addr> = request over-the-DS FT with <addr>

  wps_pbc [BSSID] = start Wi-Fi Protected Setup: Push Button Configuration

  wps_pin <BSSID> [PIN] = start WPS PIN method (returns PIN, if not hardcoded)

  wps_check_pin <PIN> = verify PIN checksum

  wps_cancel Cancels the pending WPS operation

  wps_nfc [BSSID] = start Wi-Fi Protected Setup: NFC

  wps_nfc_config_token <WPS|NDEF> = build configuration token

  wps_nfc_token <WPS|NDEF> = create password token

  wps_nfc_tag_read <hexdump of payload> = report read NFC tag with WPS data

  nfc_get_handover_req <NDEF> <WPS> = create NFC handover request

  nfc_get_handover_sel <NDEF> <WPS> = create NFC handover select

  nfc_report_handover <role> <type> <hexdump of req> <hexdump of sel> = report completed NFC handover

  wps_reg <BSSID> <AP PIN> = start WPS Registrar to configure an AP

  wps_ap_pin [params..] = enable/disable AP PIN

  wps_er_start [IP address] = start Wi-Fi Protected Setup External Registrar

  wps_er_stop = stop Wi-Fi Protected Setup External Registrar

  wps_er_pin <UUID> <PIN> = add an Enrollee PIN to External Registrar

  wps_er_pbc <UUID> = accept an Enrollee PBC using External Registrar

  wps_er_learn <UUID> <PIN> = learn AP configuration

  wps_er_set_config <UUID> <network id> = set AP configuration for enrolling

  wps_er_config <UUID> <PIN> <SSID> <auth> <encr> <key> = configure AP

  wps_er_nfc_config_token <WPS/NDEF> <UUID> = build NFC configuration token

  ibss_rsn <addr> = request RSN authentication with <addr> in IBSS

  sta <addr> = get information about an associated station (AP)

  all_sta = get information about all associated stations (AP)

  deauthenticate <addr> = deauthenticate a station

  disassociate <addr> = disassociate a station

  chan_switch <cs_count> <freq> [sec_channel_offset=] [center_freq1=] [center_freq2=] [bandwidth=] [blocktx] [ht|vht] = CSA parameters

  suspend = notification of suspend/hibernate

  resume = notification of resume/thaw

  roam <addr> = roam to the specified BSS

  p2p_find [timeout] [type=*] = find P2P Devices for up-to timeout seconds

  p2p_stop_find = stop P2P Devices search

  p2p_asp_provision <addr> adv_id=<adv_id> conncap=<conncap> [info=<infodata>] = provision with a P2P ASP Device

  p2p_asp_provision_resp <addr> adv_id=<adv_id> [role<conncap>] [info=<infodata>] = provision with a P2P ASP Device

  p2p_connect <addr> <"pbc"|PIN> [ht40] = connect to a P2P Device

  p2p_listen [timeout] = listen for P2P Devices for up-to timeout seconds

  p2p_group_remove <ifname> = remove P2P group interface (terminate group if GO)

  p2p_group_add [ht40] = add a new P2P group (local end as GO)

  p2p_prov_disc <addr> <method> = request provisioning discovery

  p2p_get_passphrase = get the passphrase for a group (GO only)

  p2p_serv_disc_req <addr> <TLVs> = schedule service discovery request

  p2p_serv_disc_cancel_req <id> = cancel pending service discovery request

  p2p_serv_disc_resp <freq> <addr> <dialog token> <TLVs> = service discovery response

  p2p_service_update = indicate change in local services

  p2p_serv_disc_external <external> = set external processing of service discovery

  p2p_service_flush = remove all stored service entries

  p2p_service_add <bonjour|upnp|asp> <query|version> <response|service> = add a local service

  p2p_service_rep asp <auto> <adv_id> <svc_state> <svc_string> [<svc_info>] = replace local ASP service

  p2p_service_del <bonjour|upnp> <query|version> [|service] = remove a local service

  p2p_reject <addr> = reject connection attempts from a specific peer

  p2p_invite <cmd> [peer=addr] = invite peer

  p2p_peers [discovered] = list known (optionally, only fully discovered) P2P peers

  p2p_peer <address> = show information about known P2P peer

  p2p_set <field> <value> = set a P2P parameter

  p2p_flush = flush P2P state

  p2p_cancel = cancel P2P group formation

  p2p_unauthorize <address> = unauthorize a peer

  p2p_presence_req [<duration> <interval>] [<duration> <interval>] = request GO presence

  p2p_ext_listen [<period> <interval>] = set extended listen timing

  p2p_remove_client <address|iface=address> = remove a peer from all groups

  wfd_subelem_set <subelem> [contents] = set Wi-Fi Display subelement

  wfd_subelem_get <subelem> = get Wi-Fi Display subelement

  fetch_anqp = fetch ANQP information for all APs

  stop_fetch_anqp = stop fetch_anqp operation

  interworking_select [auto] = perform Interworking network selection

  interworking_connect <BSSID> = connect using Interworking credentials

  interworking_add_network <BSSID> = connect using Interworking credentials

  anqp_get <addr> <info id>[,<info id>]... = request ANQP information

  gas_request <addr> <AdvProtoID> [QueryReq] = GAS request

  gas_response_get <addr> <dialog token> [start,len] = Fetch last GAS response

  hs20_anqp_get <addr> <subtype>[,<subtype>]... = request HS 2.0 ANQP information

  nai_home_realm_list <addr> <home realm> = get HS20 nai home realm list

  hs20_icon_request <addr> <icon name> = get Hotspot 2.0 OSU icon

  fetch_osu = fetch OSU provider information from all APs

  cancel_fetch_osu = cancel fetch_osu command

  sta_autoconnect <0/1> = disable/enable automatic reconnection

  tdls_discover <addr> = request TDLS discovery with <addr>

  tdls_setup <addr> = request TDLS setup with <addr>

  tdls_teardown <addr> = tear down TDLS with <addr>

  tdls_link_status <addr> = TDLS link status with <addr>

  wmm_ac_addts <uplink/downlink/bidi> <tsid=0..7> <up=0..7> [nominal_msdu_size=#] [mean_data_rate=#] [min_phy_rate=#] [sba=#] [fixed_nominal_msdu] = add WMM-AC traffic stream

  wmm_ac_delts <tsid> = delete WMM-AC traffic stream

  wmm_ac_status = show status for Wireless Multi-Media Admission-Control

  tdls_chan_switch <addr> <oper class> <freq> [sec_channel_offset=] [center_freq1=] [center_freq2=] [bandwidth=] [ht|vht] = enable channel switching with TDLS peer

  tdls_cancel_chan_switch <addr> = disable channel switching with TDLS peer <addr>

  signal_poll = get signal parameters

  pktcnt_poll = get TX/RX packet counters

  reauthenticate = trigger IEEE 802.1X/EAPOL reauthentication

  wnm_sleep <enter/exit> [interval=#] = enter/exit WNM-Sleep mode

  wnm_bss_query <query reason> = Send BSS Transition Management Query

  raw <params..> = Sent unprocessed command

  flush = flush wpa_supplicant state

  driver <command> = driver private commands

  radio_work = radio_work <show/add/done>

  vendor <vendor id> <command id> [<hex formatted command argument>] = Send vendor command

  neighbor_rep_request [ssid=<SSID>] = Trigger request to AP for neighboring AP report (with optional given SSID, default: current SSID)

  erp_flush = flush ERP keys

  mac_rand_scan <scan|sched|pno|all> enable=<0/1> [addr=mac-address mask=mac-address-mask] = scan MAC randomization

>

    常用的指令如下:

    1. 打开debug log  :   wpa_cli -iwlan0 -p/data/misc/wifi/sockets log_level debug

    2. scan:打开后扫描AP

    3. scan_results:显示扫描结果

    4. status:列出目前的联网状态。

    5. ist_networks:列出所有备选网络。目前正连接到的网络会标[CURRENT],禁用的网络会标[DISABLE]。

    6. add_network:增加一个备选网络,输出新网络的号码(这个号码替代下文的[network_id])。注意新网络此时是禁用状态。

    7. set_network [network_id] ssid “Your SSID”:设置无线网的名称(SSID)

    8. set_network [network_id] key_mgmt WPA-PSK:设置无线网的加密方式为WPA-PSK/WPA2-PSK

    9. set_network [network_id] psk “Your Password”:设置无线网的PSK密码

    10. enable_network [network_id]:启用网络。启用后如果系统搜索到了这个网络,就会尝试连接。

    11. disable_network [network_id]:禁用网络。

    12. save_config:保存配置。

e.g.

>add_network

0<---    新网络的号码

>set_network 0 ssid "TP-LINK_HyFi_75"

ok

>set_network 0 key_mgmt WPA-PSK

ok

>set_network 0 psk "147258369"

ok

>enable_network 0

ok

>save_config<--------别忘了这个,否则重启之后网络配置可能丢失

ok

 

四. demo

       wpa_supplicant log:

       wlan0: Control interface command 'SCAN TYPE=ONLY'  //scan

       wlan0: Control interface command 'ADD_NETWORK'    //add_network x :  增加一个备选网络,输出新网络的号码(这个号码替代下文的[network_id])。注意新网络此时是禁用状态

      CTRL_IFACE: ADD_NETWORK

       wlan0: Control interface command 'SET_NETWORK [REMOVED]'   //set_network [network_id] ssid “Your SSID”:设置无线网的名称(SSID

CTRL_IFACE: SET_NETWORK id=0 name='ssid'           

       ssid - hexdump(len=15): 54 50 2d 4c 49 4e 4b 5f 5a 48 45 4e 32 2e 34

       wlan0: Control interface command 'SET_NETWORK [REMOVED]'   //set_network [network_id] key_mgmt WPA-PSK:设置无线网的加密方式为WPA-PSK/WPA2-PSK

       CTRL_IFACE: SET_NETWORK id=0 name='key_mgmt'

       key_mgmt: 0x4

       wlan0: Control interface command 'SET_NETWORK [REMOVED]'   //set_network [network_id] priority x:设置network 的优先级

       CTRL_IFACE: SET_NETWORK id=0 name='priority'

       priority=0 (0x0)

       wlan0: Control interface command 'ENABLE_NETWORK 0'        //enable_network [network_id]:启用网络。启用后如果系统搜索到了这个网络,就会尝试连接

       CTRL_IFACE: ENABLE_NETWORK id=0

       wlan0: Control interface command 'SELECT_NETWORK 0'          //select_network [networi_id]:  选择network进行连接

       CTRL_IFACE: SELECT_NETWORK id=0

       Fast associate: Old scan results

       wlan0: Setting scan request: 0.000000 sec

   wlan0: Control interface command 'RECONNECT' // reconnect : like reassociate, but only takes effect if already disconnected

实操:

> scan

OK

<3>CTRL-EVENT-STATE-CHANGE id=-1 state=3 BSSID=00:00:00:00:00:00 SSID=

<3>CTRL-EVENT-SCAN-STARTED

<3>CTRL-EVENT-SCAN-RESULTS

<3>WPS-AP-AVAILABLE

<3>CTRL-EVENT-STATE-CHANGE id=-1 state=2 BSSID=00:00:00:00:00:00 SSID=

<3>CTRL-EVENT-NETWORK-NOT-FOUND

>

> scan_results

bssid / frequency / signal level / flags / ssid

04:a1:51:8a:9c:ae 5745      -53  [WPA2-PSK-CCMP][WPS][ESS]   NETGEAR-63-5G

8c:be:be:2d:3f:28  5785      -60  [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS]       XIaomi_5G

50:bd:5f:15:36:18  5785      -63  [WPA-PSK-CCMP][WPA2-PSK-CCMP][WPS][ESS]       TP-LINK_ZHEN_5G

ec:26:ca:3a:fa:ba  5745      -68  [WPA-PSK-CCMP][WPA2-PSK-CCMP][ESS]   Lw_5G

50:bd:5f:15:36:19  2442      -53  [WPA-PSK-CCMP][WPA2-PSK-CCMP][WPS][ESS]       TP-LINK_ZHEN_2.4G

8c:be:be:2d:3f:27  2437      -55  [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS]       Xiaomi_2.4G

80:89:17:ab:c0:7f  2437      -62  [WPA-PSK-CCMP][WPA2-PSK-CCMP][WPS][ESS]      sa10

ec:26:ca:87:83:02 2437      -64  [WPA-PSK-CCMP][WPA2-PSK-CCMP][ESS]   TP-LINK_8302

ec:26:ca:3a:fa:bb  2422      -65  [WPA-PSK-CCMP][WPA2-PSK-CCMP][ESS]   Lw_24G

80:89:17:ab:c0:7e 5745      -73  [WPA-PSK-CCMP][WPA2-PSK-CCMP][WPS][ESS]      sa10_5G

28:6c:07:51:1b:46 2447      -55  [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS]       Xiaomi_test_ZZ

40:e3:d6:8f:59:62  2462      -56  [WPA2-EAP-CCMP][ESS]      mtkinternet

40:e3:d6:8f:59:61  2462      -59  [WPA-EAP-CCMP+TKIP][WPA2-EAP-CCMP+TKIP][ESS]  

98:fc:11:4d:c7:a2  2412      -61  [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS]      linksys

50:bd:5f:93:ee:ac  2412      -63  [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS]      abcd

28:6c:07:51:1b:47 5745      -82  [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS]       Xiaomi_test_ZZ_5G

38:97:d6:18:c4:12 2412      -60  [WPA-PSK-TKIP][WPA2-PSK-TKIP][ESS]  wnw

c8:02:10:b4:ab:61 2462      -69  [WPA2-PSK-CCMP][ESS]      LG_MusicFlow_DL_3193

70:f9:6d:31:e0:00  2462      -75  [WPA2-PSK-CCMP][ESS]      MPR-wifi

80:89:17:f4:cb:77  2437      -78  [WPA-PSK-CCMP][WPA2-PSK-CCMP][WPS][ESS]       TP-LINK_2.4G_MT3

6c:f3:7f:38:ff:eb    5785      -85  [WPA2-EAP-CCMP][ESS]      mtkemp

6c:f3:7f:38:ff:ea    5785      -86  [WPA2-EAP-CCMP][ESS]      mtkinternet

64:09:80:1f:17:be  2462      -75  [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS]       SS2_Xiaomi

40:e3:d6:8f:59:41  2462      -75  [WPA-EAP-CCMP+TKIP][WPA2-EAP-CCMP+TKIP][ESS]  

ec:6c:9f:22:de:01  2437      -75  [WPA2-PSK-CCMP][ESS]      estar

40:e3:d6:8f:59:43  2462      -76  [WPA2-EAP-CCMP][ESS]      mtkemp

38:97:d6:18:d4:32 2412      -76  [WPA-PSK-TKIP][WPA2-PSK-TKIP][ESS]  wnw

40:e3:d6:8f:59:42  2462      -77  [WPA2-EAP-CCMP][ESS]      mtkinternet

6c:f3:7f:38:ff:e9    5785      -87  [WPA-EAP-CCMP+TKIP][WPA2-EAP-CCMP+TKIP][ESS]  

80:89:17:f4:cb:76  5785      -89  [WPA-PSK-CCMP][WPA2-PSK-CCMP][WPS][ESS]      TP-LINK_5G_MT3

b8:a3:86:55:8f:b2  2437      -79  [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS]       SS7_VPN

40:e3:d6:8f:59:83  2462      -81  [WPA2-EAP-CCMP][ESS]      mtkemp

38:97:d6:18:c4:00 5805      -85  [WPA-PSK-TKIP][WPA2-PSK-TKIP][ESS]  wnwyanfa

40:e3:d6:8f:59:81  2462      -82  [WPA-EAP-CCMP+TKIP][WPA2-EAP-CCMP+TKIP][ESS]  

0c:72:2c:4f:41:66  2427      -88  [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS]       0000aaaa

40:e3:d6:8f:59:64  2462      -57  [WEP][ESS] mtklab

40:e3:d6:8f:59:44  2462      -75  [WEP][ESS] mtklab

6c:f3:7f:38:ff:ec    5785      -86  [WEP][ESS] mtklab

04:a1:51:8a:9c:ac 2422      -56  [WPS][ESS] NETGEAR-63-2.4G

e4:d3:32:cd:74:b3 2412      -57  [WPS][ESS] rongweim

40:e3:d6:8f:59:60  2462      -57  [ESS]     mtkguest

fc:75:16:a3:95:d0  2462      -76  [WPS][ESS] dlink

00:0c:43:28:08:88 2437      -78  [ESS]     MT7623_AP_2.4G

6c:f3:7f:38:ff:e8    5785      -85  [ESS]     mtkguest

40:e3:d6:8f:59:40  2462      -75  [ESS]     mtkguest

6c:f3:7f:38:ff:e0    2462      -85  [ESS]     mtkguest

> list_network

network id / ssid / bssid / flags

0       Xiaomi_5G   any [DISABLED]

1       D8_5GHZ    any [DISABLED]

2       SS7_VPN    any [DISABLED]

3       Xiaomi_2.4G       any [DISABLED]

4       XIaomi_5G   any [DISABLED]

5       hello       any [DISABLED]

6       NETGEAR6200  any [DISABLED]

7       NETGEAR6200_5G  any [DISABLED]

8       NETGEAR-63-2.4G  any [DISABLED]

9       DLink88_24G      any [DISABLED]

> add_network 10

10

> set_network 10 ssid "NETGEAR-63-5G"

OK

> list_network                      

network id / ssid / bssid / flags

0       Xiaomi_5G   any [DISABLED]

1       D8_5GHZ    any [DISABLED]

2       SS7_VPN    any [DISABLED]

3       Xiaomi_2.4G       any [DISABLED]

4       XIaomi_5G   any [DISABLED]

5       hello       any [DISABLED]

6       NETGEAR6200  any [DISABLED]

7       NETGEAR6200_5G  any [DISABLED]

8       NETGEAR-63-2.4G  any [DISABLED]

9       DLink88_24G      any [DISABLED]

10     NETGEAR-63-5G     any [DISABLED]

> set_network 10 key_mgmt WPA-PSK   

OK

> set_network 10 psk "11111111" 

OK

> get_network 10 key_mgmt

WPA-PSK

> get_network 10 psk    

*

> enable_network 10

OK

<3>CTRL-EVENT-STATE-CHANGE id=-1 state=3 BSSID=00:00:00:00:00:00 SSID=

<3>CTRL-EVENT-SCAN-STARTED

<3>CTRL-EVENT-SCAN-RESULTS

<3>WPS-AP-AVAILABLE

<3>Trying to associate with [18434.676000] 80211> Connect bssid 04:a1:51:8a:9c:ae

> select_network 10

OK

> reconnect

OK

> list_network    

network id / ssid / bssid / flags

0       Xiaomi_5G   any [DISABLED]

1       D8_5GHZ    any [DISABLED]

2       SS7_VPN    any [DISABLED]

3       Xiaomi_2.4G       any [DISABLED]

4       XIaomi_5G   any [DISABLED]

5       hello       any [DISABLED]

6       NETGEAR6200  any [DISABLED]

7       NETGEAR6200_5G  any [DISABLED]

8       NETGEAR-63-2.4G  any [DISABLED]

9       DLink88_24G      any [DISABLED]

10     NETGEAR-63-5G     any [CURRENT]

> save_config

OK

> status

bssid=04:a1:51:8a:9c:ae

freq=5745

ssid=NETGEAR-63-5G

id=10

mode=station

pairwise_cipher=CCMP

group_cipher=CCMP

key_mgmt=WPA2-PSK

wpa_state=COMPLETED

ip_address=10.0.0.5

address=00:6c:fd:ab:68:be

uuid=12345678-9abc-def0-1234-56789abcdef0

<3>CTRL-EVENT-STATE-CHANGE id=10 state=9 BSSID=04:a1:51:8a:9c:ae SSID=NETGEAR-63-5G

<3>CTRL-EVENT-CONNECTED - connection to 04:a1:51:8a:9c:ae completed (auth) [id=10 id_str=]

 

保存后的wap_supplicant.conf

root@:/system/bin # cd /data/misc/wifi/                              

root@:/data/misc/wifi # cat wpa_supplicant

wpa_supplicant.conf wpa_supplicant/    

at wpa_supplicant.conf                                                        <

ctrl_interface=/data/misc/wifi/sockets

driver_param=p2p_capable=0

update_config=1

uuid=12345678-9abc-def0-1234-56789abcdef0

device_name=full

manufacturer= Group Co., Ltd

model_name=Android TV

model_number=Android TV

serial_number=123456789

device_type=10-0050F204-5

os_version=01020300

config_methods=physical_display virtual_push_button

external_sim=1

wowlan_triggers=magic_pkt

network={

  ssid="Xiaomi_5G"

  psk="26630099"

  key_mgmt=WPA-PSK

  priority=12

  disabled=1

}

network={

  ssid="D8_5GHZ"

  key_mgmt=NONE

  priority=9

  disabled=1

}

network={

  ssid="SS7_VPN"

  psk="12345678"

  key_mgmt=WPA-PSK

  priority=11

  disabled=1

}

network={

  ssid="Xiaomi_2.4G"

  psk="26630099"

  key_mgmt=WPA-PSK

  priority=13

  disabled=1

}

network={

  ssid="XIaomi_5G"

  psk="26630099"

  key_mgmt=WPA-PSK

  priority=18

  disabled=1

}

network={

  ssid="hello"

  key_mgmt=NONE

  priority=17

  disabled=1

}

network={

  ssid="NETGEAR6200"

  psk="12345678"

  key_mgmt=WPA-PSK

  priority=19

  disabled=1

}

network={

  ssid="NETGEAR6200_5G"

  psk="12345678"

  key_mgmt=WPA-PSK

  priority=27

  disabled=1

}

network={

  ssid="NETGEAR-63-2.4G"

  psk="11111111"

  key_mgmt=WPA-PSK

  priority=56

  disabled=1

}

network={

  ssid="DLink88_24G"

  psk="12345678"

  key_mgmt=WPA-PSK

  priority=38

  disabled=1

}

network={

  ssid="NETGEAR-63-5G"

  psk="11111111"

  key_mgmt=WPA-PSK

}

 

已标记关键词 清除标记
如题,我在使用 wpa_cli 这个命令写入wifi信息的时候感觉每次都要打很长的代码 于是写了一个bash脚本想使得写入更加轻松,但是在写入的时候遇到了变量调用的问题 希望大家能看一看哪里出了问题 代码大概如下: read -p "intput a SSID:" ssid read -p "input password of $ssid :" psk a= ./wpa_cli -i wlp5s0 add_network ./wpa_cli -i wlp5s0 set_network $a ssid '"$ssid"' ./wpa_cli -i wlp5s0 set_network $a psk '"$psk"' 如上所示 ./wpa_cli -i wlp5s0 add_network 这个命令会返回给窗口一个值(networkid),是这样子的 ![图片说明](https://img-ask.csdn.net/upload/201806/25/1529935662_296001.png) 于是我希望用 a= ./wpa_cli -i wlp5s0 add_network 这样一个命令来获取这个返回值,证明后发现是不可以的,那么我怎么样能够获得 ./wpa_cli -i wlp5s0 add_network这个命令返回给我的network id的值呢? 然后的问题也随之而来,使用 wpa_cli 命令设置这个网络的ssid和psk需要用到 $ wpa_cli -i wlan0 set_network 0 ssid '"name"' $ wpa_cli -i wlan0 set_network 0 psk '"psk"' 这两种命令 ![图片说明](https://img-ask.csdn.net/upload/201806/25/1529935997_733711.png) 这里面的name和psk外面包的是单引号加上双引号 而我想用之前获取的ssid和psk还有networkid来完成同样的操作 a= ./wpa_cli -i wlp5s0 add_network ./wpa_cli -i wlp5s0 set_network $a ssid '"$ssid"' ./wpa_cli -i wlp5s0 set_network $a psk '"$psk"' 这里面被单双引号包括的$ssid和$psk还是一个变量了吗 而运行了这个脚本之后发现确实存在问题 networkid也没有成功的用$a变量替换掉,ssid和psk也没有 ![图片说明](https://img-ask.csdn.net/upload/201806/25/1529936446_324098.png) 如图所示 请问大神们有什么方法能让我在单双引号中调用这个变量呢,转义符可以吗? 说了这么多 主要问题应该在于如何在 ‘ “ ” ’ 中引入变量 and 如何能获得创建的network id的值到一个变量上?
©️2020 CSDN 皮肤主题: 精致技术 设计师:CSDN官方博客 返回首页