Wpa_supplicant工具的使用

时间:2021-12-31 18:37:08

用的板子是Cubieboard2,串口操作的,操作过程如下:

leekwen@cubieboard2:~# cat /etc/issue
Linaro 13.04 \n \l

leekwen@cubieboard2:~# wpa_passphrase "Android2" "9876543210" > /etc/wpa_supplicant.conf
leekwen@cubieboard2:~# cat /etc/wpa_supplicant.conf
network={
ssid="Android2"
#psk="9876543210"
psk=0e3a520c30e1282bc6d656a8fd3f9178caa9cb2c04e8295658a5f3efd6e09fe7
}
leekwen@cubieboard2:~# vi /etc/wpa_supplicant.conf
network={
#请注意ssid名称的大小写
ssid="Android2"
#Robust Security Network:强健安全网络,表示这个网络配置比WEP模式要更安全
proto=RSN
#请无论你是使用WPA-PSK,WPA2-PSK,都请在这里输入 WPA-PSK。
#这在wpa_supplicant看来WPA-PSK,WPA2-PSK都是 WPA-PSK,改成WPA2-PSK,它也不认识。
key_mgmt=WPA-PSK
#wpa_supplicant目前还不认AES的加密标准,因此即使你在此输入AES也没有用,
#自行web到路由器上改成CCMP TKIP吧,就是不去修改路由器上的AES加密,这样写也是可以的
pairwise=CCMP TKIP
## 同上 ##
group=CCMP TKIP
## 密码的明码 ##
#psk="9876543210"
#wpa_supplicant算出来的密码
psk=0e3a520c30e1282bc6d656a8fd3f9178caa9cb2c04e8295658a5f3efd6e09fe7
}
leekwen@cubieboard2:~# wpa_supplicant -iwlan0 -c /etc/wpa_supplicant.conf -d &
leekwen@cubieboard2:~# route add default gw 192.168.10.1
leekwen@cubieboard2:~# echo "nameserver 202.101.272.46" >> /etc/resolv.conf
leekwen@cubieboard2:~# dhclient wlan0
leekwen@cubieboard2:~# ifconfig wlan0
wlan0 Link encap:Ethernet HWaddr 00:50:c2:d8:e7:48
inet addr:192.168.10.137 Bcast:192.168.10.255 Mask:255.255.255.0
inet6 addr: fe80::250:c2ff:fed8:e748/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:12166 errors:0 dropped:12372 overruns:0 frame:0
TX packets:10795 errors:0 dropped:1 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:16167568 (16.1 MB) TX bytes:1214627 (1.2 MB)

leekwen@cubieboard2:~# ping baidu.com
PING baidu.com (123.125.114.144) 56(84) bytes of data.
64 bytes from 123.125.114.144: icmp_req=1 ttl=50 time=31.7 ms
64 bytes from 123.125.114.144: icmp_req=2 ttl=50 time=32.1 ms
64 bytes from 123.125.114.144: icmp_req=3 ttl=50 time=34.9 ms
^C
--- baidu.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 31.739/32.945/34.973/1.442 ms

leekwen@cubieboard2:~# cat wifiup.sh
#!/bin/sh
#
# wpa_passphrase Myssid "Password Of Myssid" > /etc/wpa_supplicant.conf
#
ifconfig wlan0 up
wpa_supplicant -iwlan0 -c /etc/wpa_supplicant.conf -d &
route add default gw 192.168.10.1
echo "nameserver 202.101.272.46" >> /etc/resolv.conf
dhclient wlan0
以上命令都整合到这个脚本中了。