使用wpa supplicant连接无线

来自三线的随记
Admin讨论 | 贡献2018年12月14日 (五) 22:07的版本

使用 wpa_supplicant的客户端工具wpa_cli连接无线

wpa_supplicant包含两个主要的可执行工具:wpa_supplicant和wpa_cli。wpa_supplicant是核心程序,它和wpa_cli的关系就是服务和客户端的关系:后台运行wpa_supplicant,使用wpa_cli来搜索、设置、和连接网络。

在wpa_cli交互模式下可以执行很多命令 ,使用命令

wpa_cli -h 

man wpa_cli

查看相关介绍

1.运行服务端wpa_supplicant

wpa_supplicant -i<wlan0> -D<driver> -B -c</etc/wpa_supplicant/wpa_supplicant.conf

*部分linux发行版默认wpa_supplicant服务已运行,使用top命令查询,已运行则不需要再执行此命令,-D参数部分情况下不需要

步骤

1.运行服务端wpa_supplicant

wpa_supplicant -i<wlan0> -D<driver> -B -c </etc/wpa_supplicant/wpa_supplicant.conf>

*部分linux发行版默认wpa_supplicant服务已运行,使用top命令查询,已运行则不需要再执行此命令,-D参数部分情况下不需要

2.运行客户端wpa_cli

wpa_cli -i<ifname> -p<path to ctrl sockets>

*不使用-i参数则使用默认网卡,-p

3.

scan

scan_result

add_network

*注意回显编号

set_network 0 ssid "ssid"

set_network 0 psk "psk"

select_network 0

enable_network 0

*0为network编号

list_network

status

save_config

quit

dhclient <ifname>

*获取ip地址

for AP that doesn`t have encryption

>add_network (It will display a network id for you, assume it returns 0)

>set_network 0 ssid “666”

>set_network 0 key_mgmt NONE

>enable_network 0

>quit

for AP that has WEP

>add_network (assume returns 1)

>set_network 1 ssid “666”

>set_network 1 key_mgmt NONE

>set_network 1 wep_key0 “your ap passwork”(if usting ASCII, it need

double quotation marks, if using hex, then don`t need the double quotation

marks)

>set_network 1 wep_tx_keyidx 0

>select_network 1 (optional, remember, if you are connecting with another

AP, you should select it to disable the another)

>enable_network 1

for AP that has WPA-PSK/WPA2-PSK

>add_network (assume returns 2)

>set_network 2 ssid “666”

>set_network 2 psk “your pre-shared key”

>select_network 2 (optional, remember, if you are connecting with another

AP, you should select it to disable the another

>enable_network 2

wpa_supplicant -iwlan1 -C /var/run/wpa_supplicant/ -c /etc/wpa_supplicant/wpa_supplicant.conf -B -u -s -O /run/wpa_supplicant

wpa_supplicant -iwlan1 -C /var/run/wpa_supplicant/ -c /etc/wpa_supplicant/wpa_supplicant.conf -B

apt-get install wireless-tools

PS:http://blog.csdn.net/zhandoushi1982/article/details/24097775