Android如何通过命令行获取WiFi列表以及参数:

一个工具加一个参数:

wpa_cli => The command line interface of wpa_supplicant

wifi interface socket目录


一般Android习题WiFi所对应着的interface名为wlan0,若不一样请参看init.{xxx}.rc中启动wpa_supplicant daemon的参数,或通过getprop查询得到。

找到带有wlan0 socket文件的目录,比如

/data/misc/wifi/
在我的手机上(Android 4.2.2)为/dev/socket/
然后adb shell
通过-p 选项指定socket文件目录
root@android:/dev/socket # wpa_cli -p /dev/socket/                             wpa_cli v2.0-devel-Copyright (c) 2004-2012, Jouni Malinen <j@w1.fi> and contributorsThis software may be distributed under the terms of the BSD license.See README for more details.Selected interface 'wpa_wlan0'Interactive mode<3>CTRL-EVENT-SCAN-RESULTS > > <3>CTRL-EVENT-SCAN-RESULTS > scanFAIL-BUSY<3>CTRL-EVENT-SCAN-RESULTS > scanOK<3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS > scan_resultsbssid / frequency / signal level / flags / ssid80:81:00:e3:ee:882447-42[ESS]alipay-wifi-podinns1c:aa:07:c6:ea:102412-49[WPA-EAP-TKIP][WPA2-EAP-TKIP+CCMP][ESS]alibaba-incbc:d1:77:9c:12:522437-68[WPA-PSK-CCMP][WPA2-PSK-CCMP][WPS][ESS]21F_ISV38:22:d6:4d:e9:602412-75[ESS]CMCC00:87:36:39:e4:df2462-75[ESS]mike.lx38:22:d6:4d:a1:302412-72[ESS]CMCC1c:aa:07:c7:24:b02462-75[WPA-EAP-TKIP][WPA2-EAP-TKIP+CCMP][ESS]alibaba-inc1c:aa:07:c7:24:b22462-75[ESS]alilang-setupc8:3a:35:07:e4:c82412-82[WPA2-PSK-CCMP][ESS]mars-new9e:21:6a:01:54:302437-55[ESS]-UFreet-3c:ce:73:c6:5d:632412-69[ESS]alilang-setup1c:aa:07:f5:81:b02462-93[WPA-EAP-TKIP][WPA2-EAP-TKIP+CCMP][ESS]alibaba-inc1c:aa:07:c7:1a:712412-76[ESS]alibaba-guest1c:aa:07:c6:ea:122412-55[WPA-EAP-TKIP][WPA2-EAP-TKIP+CCMP][ESS]alipay-pre1c:aa:07:f5:85:322437-96[ESS]alilang-setup1c:aa:07:f5:81:b22462-77[WPA-EAP-TKIP][WPA2-EAP-TKIP+CCMP][ESS]alipay-pre1c:aa:07:c7:1a:702412-81[WPA-EAP-TKIP][WPA2-EAP-TKIP+CCMP][ESS]alibaba-inc1c:aa:07:c6:ea:112412-54[ESS]alibaba-guest1c:aa:07:c7:24:b12462-75[ESS]alibaba-guest1c:aa:07:c7:1a:722412-79[WPA-EAP-TKIP][WPA2-EAP-TKIP+CCMP][ESS]alipay-pre3c:ce:73:c6:5d:612412-69[ESS]alibaba-guest<3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS > list_networksnetwork id / ssid / bssid / flags0xiaodaiany1alibaba-incany[CURRENT]277.NETany3alipay-wifi-podinnsany4alilang-setupany5CMCCany<3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS <3>CTRL-EVENT-SCAN-RESULTS 

获得当前连接详细参数:
> signal_pollRSSI=-28LINKSPEED=65NOISE=-97FREQUENCY=2412

其他命令(极其丰富):
> helpcommands:  status [verbose] = get current WPA/EAPOL/EAP status  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 = show this 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)  get <name> = get information  logon = IEEE 802.1X EAPOL state machine logon  logoff = IEEE 802.1X EAPOL state machine logoff  pmksa = show PMKSA cache  reassociate = force reassociation  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  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  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  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> = get capabilies  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)  sched_scan_intervals <short_interval> <long_interval> <num_short_intervals>    Set sched scan intervals parameters    <short|long_interval> = intervals values (in seconds)    <num_short_intervals> = num of intervals to use short_interval  bss_expire_age <value> = set BSS expiration age parameter  bss_expire_count <value> = set BSS expiration scan count parameter  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_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  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  suspend = notification of suspend/hibernate  resume = notification of resume/thaw  drop_sa = drop SA without deauth/disassoc (test command)  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_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> <query|version> <response|service> = add a local 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  wfd_subelem_set <subelem> [contents] = set Wi-Fi Display subelement  wfd_subelem_get <subelem> = get Wi-Fi Display subelement  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>  signal_poll = get signal parameters  reauthenticate = trigger IEEE 802.1X/EAPOL reauthentication  driver <command> = driver private commands
  
  

更多相关文章

  1. Android一级目录介绍
  2. android 创建文件夹失败
  3. Android从文件目录中写入和读取图片
  4. 布局文件中的笔记
  5. 学习目录
  6. 【Android】配置文件属性说明

随机推荐

  1. Android(安卓)APP 版本更新通知代码
  2. [置顶] Android加载数据过程中的菊花显示
  3. Android开发学习笔记整理(16)-网络请求
  4. 【转】Android(安卓)SDK版本与API Level
  5. Android(安卓)添加快捷方式
  6. android发送json并解析返回json
  7. Android为HttpClient设置证书(用户名和密
  8. android 与其他程序交互(一)
  9. [Android] ListView 结合SimpleAdapter使
  10. Android(安卓)ListView