wpa_cli 操作指令的基本使用

1、简介 :

wpa_supplicant是配置开发wifi的常用工具,该工具包含wpa_supplicant和wpa_cli 这2个程序。其中wpa_supplicant 程序相当于服务端在后台运行,wpa_cli 相当于客户端。wpa_supplicant 会响应wpa_cli 的请求,从而实现WiFi的配置连接或者信息更改。

wpa_supplicant工具支持wep、wpa、wpa2等加密认证方式。

2、wpa_cli 的使用 

根据其他博客的方式,直接使用这样的方式,会把报错。在我自己的板子上会报错,因为网卡不同,或者说配置文件的路径不同。

wpa_cli -i wlan0 scan 

 因此,我们通过使用指定路径的方式,进行运行

首先运行 ifconfig  可以指导网卡的名称

ifconfig

然后 使用以下命令(根据自己的文件路径进行指定就可以了 )

wpa_cli -ieth2 -p /var/run/wpa_supplicant -s  /var/run/wpa_supplicant

这样,就可以进行命令的输入了。

3、常用命令的使用

命令返回值含义备注
scanok搜索wifi 
scan_resultswifi名称搜到到的全部wifi名称等信息 
set_networkok设置wifi的SSID和psk 
list_network列出所有的配置文件中的信息列出保存的文件中的所有信息 
add_network添加一个网络添加一个网络 
save_networkOK将配置保存 
remove_network删除一个网络,根据网络ID删除删除一个网络ID,根据网络ID删除 

 

 

 

 

 

 

 

 

 

 

 

4、举个例子

如果要连接加密方式是[WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS] (wpa加密),wifi名称是namewifi密码是:psk

首先通过   list_network  将wifi 信息 全部列出。从这里可以看出当前有哪些网络信息。network_id   ssid   bssid   flags 。其中flags 表明,当前所使用的wifi连接。(想一下自己的手机使用的wifi 的时候,也曾连接多个wifi,连接过的那些都会在你的配置文件里,但是使用的就只是当前的一个。其他的都是disable状态。这样有助于自己理解

以下是一个使用的当时。前面两行是设置SSID 和 密码。第三行是保存配置,如果不保存的话,重启之后就失败了。第四第五行,就是将配置的生效。

wpa_cli -ieth2 -p /var/run/wpa_supplicant -s  /var/run/wpa_supplicant set_network 0 ssid '"wifitest"'

wpa_cli -ieth2 -p /var/run/wpa_supplicant -s  /var/run/wpa_supplicant set_network 0 psk '"12345678"'

wpa_cli -ieth2 -p /var/run/wpa_supplicant -s  /var/run/wpa_supplicant save_config

wpa_cli -ieth2 -p /var/run/wpa_supplicant -s  /var/run/wpa_supplicant disable_network 0

wpa_cli -ieth2 -p /var/run/wpa_supplicant -s  /var/run/wpa_supplicant enable_network 0

 

 

5、 附件

使用help 命令,可以显示所有的wpa_cli 的命令

wpa_cli -ieth2 -p /var/run/wpa_supplicant -s  /var/run/wpa_supplicant help

一个表格

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
  driver_flags  list driver flags
  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
  abort_scan  request ongoing scan to be aborted
  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> <create> <type>  adds new interface, all parameters but
    <ifname> are optional. Supported types are station ('sta') and AP ('ap') 
  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_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
  suspend  notification of suspend/hibernate
  resume  notification of resume/thaw
  roam <addr>  roam to the specified BSS
  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>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 3
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值