wpa_supplicant 配置与应用

2024-06-19 18:38
文章标签 配置 应用 wpa supplicant

本文主要是介绍wpa_supplicant 配置与应用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

wpa_supplicantwifi客户端(client)加密认证工具,和iwconfig不同,wpa_supplicant支持wepwpawpa2等完整的加密认证,而iwconfig只能支持wep

wpa_supplocant相对应的,ap端的加密认证工具为hostapd

wpa_supplicant运行于后台,它需要借助控制台工具wpa_cli来进行手动操作。

  1. wpa_supplicant配置文件

    1. Config文件

wpa_supplicant源码目录下,存在参考的配置文件wpa_supplicant.conf,几乎包含里所有的配置项。

我们的配置文件不需要这么复杂,开始测试阶段,我只写最简单的配置文件,其它手动操作先。

/etc/下建立配置文件wpa_supplicant.conf,内容如下:

ctrl_interface=/var/run/wpa_supplicant

update_config=1

其中,update_config=1使能配置更改。

 

    1. wpa_supplicant参数

wpa_supplicant可以通过如下命令查看其所有操作参数:

 

#wpa_supplicant --help

wpa_supplicant: invalid option -- -

wpa_supplicant v0.8.x

Copyright (c) 2003-2011, Jouni Malinen and contributors

This program is free software. You can distribute it and/or modify it

under the terms of the GNU General Public License version 2.

Alternatively, this software may be distributed under the terms of the

BSD license. See README and COPYING for more details.

 

usage:

wpa_supplicant [-BddhKLqqstuvW] [-P] [-g] \

-i -c [-C] [-D] [-p] \

[-b] [-f] [-e] \

[-o] [-O] \

[-N -i -c [-C] [-D] \

[-p] [-b] ...]

 

drivers:

athr = Atheros Linux 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)

-i = interface name

-d = increase debugging verbosity (-dd even more)

-D = driver name (can be multiple drivers: nl80211,wext)

-e = entropy file

-g = global ctrl_interface

-K = include keys (passwords, etc.) in debug output

-t = include timestamp in debug messages

-h = show this help text

-L = show license (GPL and BSD)

-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)

-v = show version

-W = wait for a control interface monitor before starting

-N = start describing new interface

example:

wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf

 

其中最常用的为:-i 指定端口,-c 指定配置文件,-D 指定使用的wifi驱动

我们这里只指定端口和配置文件,驱动使用默认的。

wpa_supplicant启动操作命令如下:

#wpa_supplicant -i ath0 -c /etc/wpa_supplicant.conf &

 

注意:启动wpa_supplicant之前wifi必须先启动,wpa_supplicnat使用在wifi client端口上。

 

在测试过程中,如果出现问题,可以在wpa_supplicant启动时使用参数使其输出更多的debug信息:

#wpa_supplicant -i ath0 -c /etc/wpa_supplicant.conf -dddd

  1. 手动操作

wpa_supplicant启动后,就可以通过wpa_cli来操作设置了。

wpa_cli操作有两种方法,一是直接进入CLI控制台操作,如下:

#wpa_cli

# wpa_cli

wpa_cli v0.8.x

Copyright (c) 2004-2011, Jouni Malinen and contributors

 

This program is free software. You can distribute it and/or modify it

under the terms of the GNU General Public License version 2.

 

Alternatively, this software may be distributed under the terms of the

 

BSD license. See README and COPYING for more details.

 

Selected interface 'ath0'

 

Interactive mode

 

> add

0

> list_network

network id / ssid / bssid / flags

0 any [DISABLED]

>

 

另一种是直接在终端中敲击完整的命令行操作,如下:

# wpa_cli -i ath0 set_network 0 ssid '"206"'

OK

 

这两种方法的效果是一样的,主要区别如下:

  • wpa_cli控制台中写的命令行要简单些,不需要指定端口(wpa_cli –i ath0),但写错了不能回退,需要重新完整写入

  • 终端写入的命令行长写,但写错里可以回退重新写。

  • 对于ssid和密码,终端中操作时需要使用单引号把双引号的字符包括起来,而cli控制台中只需要双引号,如下:

 

 

> set_network 0 psk "12345678"

OK

 

wpa_cli支持的所有命令可以通过help操作来查看

> help

 

 

    1. 扫描于连接

以下是我的一个完整的扫描连接过程:

  1. 启动wpa_supplicantwpa_cli.

# wpa_supplicant -i ath0 -c /etc/wpa_supplicant.conf &

# wpa_cli

 

  1. 扫描ap

使用scan命令扫描网络,结束后使用scan_results命令查看网络。

> scan

OK

> driver_atheros_event_wireless: scan result event - SIOCGIWSCAN

<3>CTRL-EVENT-SCAN-RESULTS

<3>WPS-AP-AVAILABLE

 

> > scan_results

bssid / frequency / signal level / flags / ssid

00:23:68:26:40:c8 2412 36 [ESS] CMCC

00:26:5a:26:33:ac 2437 38 [WPA-PSK-TKIP][WPA2-PSK-TKIP][WPS][ESS] LZ205

>

 

  1. 增加网络

使用add_network命令增加一个网络,可以使用list_network查看增加的网络信息。

> add_network

0

> list_network

network id / ssid / bssid / flags

0 any [DISABLED]

 

  1. 设定网络连接的ssid和密码

使用set_network命令设定连接的ap的用户名和密码

> set_network 0 ssid "LZ205"

OK

> set_network 0 psk "20100208"

OK

 

  1. 使能网络连接

使用enable_network命令使能网络连接

> enable_network 0

OK

> driver_atheros_event_wireless: scan result event - SIOCGIWSCAN

ath0: Trying to associate with 00:26:5a:26:33:ac (SSID='LZ205' freq=2437 MHz)

<3>CTRL-EVENT-SCA ieee80211_ioctl_setmlme: os_opmode=1

[ieee80211_ioctl_setmlme] set desired bssid 00:26:5a:26:33:ac

N-RESULTS

<3>WPS-AP-AVAILABLE

<3>Trying to associate with 00:26:5a:26:33:ac (SSID='LZ205' freq=2437 MHz)

ath_paprd_cal PAPRD excessive failure disabling PAPRD now

ath0: Associated with 00:26:5a:26:33:ac

<3>Associated with 00:26:5a:26:33:ac

vap-0: mlme_sta_swbmiss_timer_handler: SW Beacon miss!!

vap-0: mlme_sta_swbmiss_timer_handler: SW Beacon miss!!

vap-0: ieee80211_vap_iter_beacon_miss: Beacon miss, will indicate to OS!!

ath0: WPA: 4-Way Handshake failed - pre-shared key may be incorrect

<3>WPA: 4-Way Handshake failed - pre-shared key may be incorrect

ath0: CTRL-EVENT-DISCONNECTED bssid=00:26:5a:26:33:ac reason=0

<3>CTRL-EVENT-DISCONNECTED bssid=00:26:5a:26:33:ac reason=0

ieee80211_ioctl_setmlme: os_opmode=1 sult event - SIOCGIWSCAN

[ieee80211_ioctl_setmlme] set desired bssid 00:26:5a:26:33:ac

 

<3>CTRL-EVENT-SCAN-RESULTS

<3>WPS-AP-AVAILABLE

ath0: Trying to associate with 00:26:5a:26:33:ac (SSID='LZ205' freq=2437 MHz)

<3>Trying to associate with 00:26:5a:26:33:ac (SSID='LZ205' freq=2437 MHz)

ath0: Associated with 00:26:5a:26:33:ac

<3>Associated with 00:26:5a:26:33:ac

ath0: WPA: Key negotiation completed with 00:26:5a:26:33:ac [PTK=TKIP GTK=TKIP]

<3>WPA: Key negotiation completed with 00:26:5a:26:33:ac [PTK=TKIP GTK=TKIP]

ath0: CTRL-EVENT-CONNECTED - Connection to 00:26:5a:26:33:ac completed (auth) [id=0 id_str=]

<3>CTRL-EVENT-CONNECTED - Connection to 00:26:5a:26:33:ac completed (auth) [id=0 id_str=]

 

看到CTRL-EVENT-CONNECTED信息,表示连接完成。

  1. 状态查看

使用status命令可以查看网络状态,使用quit退出CLI后,可以使用iwconfig命令查看ath0连接状态。

> status

bssid=00:26:5a:26:33:ac

ssid=LZ205

id=0

mode=station

pairwise_cipher=TKIP

group_cipher=TKIP

key_mgmt=WPA2-PSK

wpa_state=COMPLETED

address=20:13:08:15:16:13

 

  1. config保存

使用save命令可以保存当前的连接设置,下次wifi启动时会自动连接此AP.

保存后,wpa_supplicant.conf文件被自动修改为如下内容:

ctrl_interface=/var/run/wpa_supplicant

update_config=1

device_type=0-00000000-0

 

network={

ssid="LZ205"

psk="20100208"

}

 

 

  1. 自动连接

若希望wifi启动后自动连接到预先设置的ap,只需按如下设置脚本即可以,如果预先设置里多个ap则每个网络需要设置优先级参数priority

ctrl_interface=/var/run/wpa_supplicant

update_config=1

 

network={

ssid="LZ205"

psk="20100208"

priority=2

}

这篇关于wpa_supplicant 配置与应用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1075832

相关文章

Zookeeper安装和配置说明

一、Zookeeper的搭建方式 Zookeeper安装方式有三种,单机模式和集群模式以及伪集群模式。 ■ 单机模式:Zookeeper只运行在一台服务器上,适合测试环境; ■ 伪集群模式:就是在一台物理机上运行多个Zookeeper 实例; ■ 集群模式:Zookeeper运行于一个集群上,适合生产环境,这个计算机集群被称为一个“集合体”(ensemble) Zookeeper通过复制来实现

CentOS7安装配置mysql5.7 tar免安装版

一、CentOS7.4系统自带mariadb # 查看系统自带的Mariadb[root@localhost~]# rpm -qa|grep mariadbmariadb-libs-5.5.44-2.el7.centos.x86_64# 卸载系统自带的Mariadb[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7

中文分词jieba库的使用与实景应用(一)

知识星球:https://articles.zsxq.com/id_fxvgc803qmr2.html 目录 一.定义: 精确模式(默认模式): 全模式: 搜索引擎模式: paddle 模式(基于深度学习的分词模式): 二 自定义词典 三.文本解析   调整词出现的频率 四. 关键词提取 A. 基于TF-IDF算法的关键词提取 B. 基于TextRank算法的关键词提取

水位雨量在线监测系统概述及应用介绍

在当今社会,随着科技的飞速发展,各种智能监测系统已成为保障公共安全、促进资源管理和环境保护的重要工具。其中,水位雨量在线监测系统作为自然灾害预警、水资源管理及水利工程运行的关键技术,其重要性不言而喻。 一、水位雨量在线监测系统的基本原理 水位雨量在线监测系统主要由数据采集单元、数据传输网络、数据处理中心及用户终端四大部分构成,形成了一个完整的闭环系统。 数据采集单元:这是系统的“眼睛”,

hadoop开启回收站配置

开启回收站功能,可以将删除的文件在不超时的情况下,恢复原数据,起到防止误删除、备份等作用。 开启回收站功能参数说明 (1)默认值fs.trash.interval = 0,0表示禁用回收站;其他值表示设置文件的存活时间。 (2)默认值fs.trash.checkpoint.interval = 0,检查回收站的间隔时间。如果该值为0,则该值设置和fs.trash.interval的参数值相等。

NameNode内存生产配置

Hadoop2.x 系列,配置 NameNode 内存 NameNode 内存默认 2000m ,如果服务器内存 4G , NameNode 内存可以配置 3g 。在 hadoop-env.sh 文件中配置如下。 HADOOP_NAMENODE_OPTS=-Xmx3072m Hadoop3.x 系列,配置 Nam

csu 1446 Problem J Modified LCS (扩展欧几里得算法的简单应用)

这是一道扩展欧几里得算法的简单应用题,这题是在湖南多校训练赛中队友ac的一道题,在比赛之后请教了队友,然后自己把它a掉 这也是自己独自做扩展欧几里得算法的题目 题意:把题意转变下就变成了:求d1*x - d2*y = f2 - f1的解,很明显用exgcd来解 下面介绍一下exgcd的一些知识点:求ax + by = c的解 一、首先求ax + by = gcd(a,b)的解 这个

wolfSSL参数设置或配置项解释

1. wolfCrypt Only 解释:wolfCrypt是一个开源的、轻量级的、可移植的加密库,支持多种加密算法和协议。选择“wolfCrypt Only”意味着系统或应用将仅使用wolfCrypt库进行加密操作,而不依赖其他加密库。 2. DTLS Support 解释:DTLS(Datagram Transport Layer Security)是一种基于UDP的安全协议,提供类似于

hdu1394(线段树点更新的应用)

题意:求一个序列经过一定的操作得到的序列的最小逆序数 这题会用到逆序数的一个性质,在0到n-1这些数字组成的乱序排列,将第一个数字A移到最后一位,得到的逆序数为res-a+(n-a-1) 知道上面的知识点后,可以用暴力来解 代码如下: #include<iostream>#include<algorithm>#include<cstring>#include<stack>#in

zoj3820(树的直径的应用)

题意:在一颗树上找两个点,使得所有点到选择与其更近的一个点的距离的最大值最小。 思路:如果是选择一个点的话,那么点就是直径的中点。现在考虑两个点的情况,先求树的直径,再把直径最中间的边去掉,再求剩下的两个子树中直径的中点。 代码如下: #include <stdio.h>#include <string.h>#include <algorithm>#include <map>#