wpa_supplicant使用

1.wpa_supplicant简介

wpa_supplicant是一个连接、配置WIFI的工具,它主要包含wpa_supplicant与wpa_cli两个程序。wpa_supplicant是服务端,wap_cli是客户端,一般情况下使用wpa_cli就可以操作WiFi。但是它不支持所有的驱动,可以浏览wpa_supplicant网站获得它所支持的驱动列表。另外,wpa_supplicant目前只能连接到那些你已经配置好SSID的无线网络,也就是使用前需要配置好wpa_supplicant的配置文件wpa_supplicant.conf
看下wpa_supplicant的help信息

[root@eufy /oem]$ wpa_supplicant -help
wpa_supplicant v2.6
usage:
  wpa_supplicant [-BddhKLqqtvW] [-P<pid file>] [-g<global ctrl>] \
        [-G<group>] \
        -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] [-p<driver_param>] \
        [-b<br_ifname>] [-e<entropy file>] [-f<debug file>] \
        [-o<override driver>] [-O<override ctrl>] \
        [-N -i<ifname> -c<conf> [-C<ctrl>] [-D<driver>] \
        [-p<driver_param>] [-b<br_ifname>] [-I<config file>] ...]

drivers:
  nl80211 = Linux nl80211/cfg80211
  wext = Linux wireless extensions (generic)
  wired = Wired Ethernet driver
options:
  -b = optional bridge interface name
  -B = run daemon in the background
  -c = Configuration file
  -C = ctrl_interface parameter (only used if -c is not)
  -d = increase debugging verbosity (-dd even more)
  -D = driver name (can be multiple drivers: nl80211,wext)
  -e = entropy file
  -f = log output to debug file instead of stdout
  -g = global ctrl_interface
  -G = global ctrl_interface group
  -h = show this help text
  -i = interface name
  -I = additional configuration file
  -K = include keys (passwords, etc.) in debug output
  -L = show license (BSD)
  -M = start describing new matching interface
  -N = start describing new interface
  -o = override driver parameter for new interfaces
  -O = override ctrl_interface parameter for new interfaces
  -p = driver parameters
  -P = PID file
  -q = decrease debugging verbosity (-qq even less)
  -t = include timestamp in debug messages
  -v = show version
  -W = wait for a control interface monitor before starting
example:
  wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wpa_supplicant.conf

选项详解

选项说明
-boptional bridge interface name 增加网桥名称
-Brun daemon in the background后台执行
-cConfiguration file 附加配置文件,即根据配置文件执行操作
-Cctrl_interface parameter (only used if -c is not) 控制网口参数
-iinterface name 设定操作的网口
-dincrease debugging verbosity (-dd even more)增加调试信息输出
-Ddriver name (can be multiple drivers: nl80211,wext) 驱动名称
-gglobal ctrl_interface 全局网口配置
-Kinclude keys (passwords, etc.) in debug output 在debug输出中包含keys
-tinclude timestamp in debug messages 将各个debug信息前输出时间标签
-hshow this help text显示帮助信息
-Lshow license (GPL and BSD) 显示license
-ooverride driver parameter for new interfaces 覆盖driver参数
-Ooverride ctrl_interface parameter for new interfaces 覆盖ctrl_interface参数
-pdriver parameters 携带驱动参数
-PPID file进程文件
-qdecrease debugging verbosity (-qq even less)在debug 中不输出指定参数
-vshow version 显示版本信息
-Wwait for a control interface monitor before starting 启动前等待控制接口
-Nstart describing new interface 启动对新接口的描述
-flog output to debug file instead of stdout log的输出文件

wpa_supplicant配置文件编写

wpa_supplicant配置文件wpa_supplicant.conf的可配置选项太多,先了解下常用的配置项。看个例子:

cat wpa_supplicant.conf
ctrl_interface=/var/run/wpa_supplicant
ap_scan=1
network={
	scan_ssid=1
	ssid="mr112"
	psk="123456789"
	key_mgmt=WPA-PSK
}

配置项说明
ctrl_interface默认的也是推荐使用的存放套接字的目录,wpa_cli将会在尝试和wpa_supplicant连接时使用它
ap_scan接入点的扫描和选择
scan_ssid=0不扫描这个通过特定的探测请求帧得到的SSID(默认)=1扫描通过特定探测请求帧得到的SSID(这个可以用于寻找不接受广播的APs或者使用多SSIDs ;这个将会增加扫描延时时间,所以在有必要时才激活此选项)
ssid无线名称
psk无线密码
key_mgmt公认的认证密钥管理协议列表,WPA-PSK 预共享密匙 (这需要‘psk’字段)

另外,如果需要休眠唤醒功能,则加wowlan_triggers=any配置

wpa_suppcliant举例

wpa_supplicant -B -i wlan0 -c /data/cfg/wpa_supplicant.confg -f /tmp/wap.log

2.wpa_cli使用

选项说明
scan打开后扫描AP
scan_results或scan_r显示扫描结果
status列出目前的联网状态。
list_networks列出所有备选网络。目前正连接到的网络会标[CURRENT],禁用的网络会标[DISABLE]。
add_network增加一个备选网络,输出新网络的号码(这个号码替代下文的[network_id])。注意新网络此时是禁用状态。
set_network [network_id] ssid “Your SSID”设置无线网的名称(SSID)
set_network [network_id] key_mgmt WPA-PSK设置无线网的加密方式为WPA-PSK/WPA2-PSK
set_network [network_id] psk “Your Password”设置无线网的PSK密码
enable_network [network_id]启用网络。启用后如果系统搜索到了这个网络,就会尝试连接。
disable_network [network_id]禁用网络。
save_config保存配置。

举例

1.搜索网络
[root@eufy /oem]$ wpa_cli scan
Selected interface 'wlan0'
OK
[root@eufy /oem]$ wpa_cli scan_result
Selected interface 'wlan0'
bssid / frequency / signal level / flags / ssid
2a:47:3d:62:21:fb	2462	-16	[WPA2-PSK-CCMP][ESS]	mr112
64:6e:97:0c:c9:68	2462	-51	[WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS]	LdRobotAp-2.4
f8:8c:21:67:6b:67	2462	-28	[WPA-PSK-CCMP][WPA2-PSK-CCMP][ESS]	app\xe7\xbb\x84
80:ea:07:81:24:85	2462	-75	[WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS]	YAKO_2.4G
f8:8c:21:67:6b:69	5785	-32	[WPA-PSK-CCMP][WPA2-PSK-CCMP][ESS]	app\xe7\xbb\x84-5G
74:22:bb:89:0c:34	5180	-38	[WPA2-PSK-CCMP][ESS]	WFW_5G
2c:15:e1:3d:ba:0d	5745	-37	[WPA2-PSK-CCMP][ESS]	ASUS_0B_5G
48:0e:ec:8d:4f:7f	5805	-40	[WPA-PSK-CCMP][WPA2-PSK-CCMP][ESS]	TP-LINK_4F7D
2.查看状态
[root@eufy /oem]$ wpa_cli status
Selected interface 'wlan0'
bssid=2a:47:3d:62:21:fb
freq=2462
ssid=mr112
id=0
mode=station
pairwise_cipher=CCMP
group_cipher=CCMP
key_mgmt=WPA2-PSK
wpa_state=COMPLETED
ip_address=192.168.191.5
address=20:32:33:38:32:72

源码分析

  • 15
    点赞
  • 128
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
wpa_supplicant是一个连接、配置WIFI的工具,它包含了wpa_supplicant和wpa_cli两个程序。wpa_supplicant是核心程序,负责后台运行并处理与网络的连接和配置。而wpa_cli是wpa_supplicant的客户端程序,用于搜索、设置和连接网络。 要启动wpa_supplicant应用,可以使用以下命令: wpa_supplicant -Dnl80211 -c /etc/wpa_supplicant.conf -i wlan0 -B 其中,-D参数指定WiFi驱动程序,可以是nl80211或wext。-c参数指定配置文件的路径,-i参数指定接口名称,-B参数表示在后台运行守护进程。 另外,如果不支持nl80211驱动程序,可以使用以下命令启动wpa_supplicantwpa_supplicant -D wext -c /etc/wpa_supplicant.conf -i wlan0 & 这个命令会在后台运行wpa_supplicant,并指定使用wext驱动程序。 在配置文件wpa_supplicant.conf中,可以设置一些参数来配置wpa_supplicant的行为。例如,"scan_ssid"参数可用于指定是否扫描隐藏的SSID,"ssid"参数指定要连接的无线网络的SSID,"psk"参数指定网络的密码,"priority"参数指定网络的连接优先级。 总结起来,要启动wpa_supplicant,可以使用命令wpa_supplicant,并指定适当的参数和配置文件。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [wpa_supplicant 启动过程(android P/9.0)](https://blog.csdn.net/kv110/article/details/103647814)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [wpa_supplicant使用方法(WiFi工具)](https://blog.csdn.net/lhb0709/article/details/109068974)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值