Categories
Dairy

2013-11-15

搞了半天终于有点斩获了,写些经验:
1.不要一开始就尝试连接加密网络,应该先从不加密网络连起(如自己用无线路由建立的开放无线网络fover0932);
2.用厂商自带的驱动,这是为硬件量身定做的,兼容性,可靠性是最好的,不要一开始就尝试用网络上复杂的使用芯片厂家驱动的办法;
3.不要沉溺于手册,对wpa耿耿于怀,应该从简单的通用命令开始,如iwlist、iwconfig等;
阶段效果:可以用网卡连上自建的开放wifi,方法如下:
1.用自己的无线路由建立开放热点’fover0932’,并打开DHCP服务;
2.找到NetCore自带的Linux下的网卡驱动程序”RTL8192CU_8188CUS_8188CE-VAU_linux_v3.0.2164.20110715″;
3.# ifconfig wlan2 up 打开无线网卡;
4.# iwlist wlan2 scan 找到热点fover0932的MAC地址是“28:2C:B2:9E:79:D0”
“Cell 05 – Address: 28:2C:B2:9E:79:D0
ESSID:”fover0932″
Protocol:IEEE 802.11bgn
Mode:Master
Frequency:2.462 GHz (Channel 11)
Encryption key:off
Bit Rates:300 Mb/s
IE: Unknown: DD310050F204104A00011010440001021047001000000000000010000000282CB29E79D0103C0001011049000600372A000120
Quality=100/100 Signal level=100/100″;
5.# iwconfig wlan2 ap 28:2C:B2:9E:79:D0 以MAC方式连接到fover0932热点,连上后并没有任何显示,可以通过 # iwconfig wlan2 来查看,其结果为(显示已经连上了热点fover0932):
“wlan2 IEEE 802.11bgn ESSID:”fover0932″ Nickname:”
Mode:Managed Frequency:2.462 GHz Access Point: 28:2C:B2:9E:79:D0
Bit Rate:150 Mb/s Sensitivity:0/0
Retry:off RTS thr:off Fragment thr:off
Power Management:off
Link Quality=100/100 Signal level=100/100 Noise level=0/100
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0”;
6.# dhclient wlan2 用dhclient工具获取IP地址,其显示如下(表示已经成功获取到IP地址192.168.1.101):
“Internet Systems Consortium DHCP Client V3.1.3
Copyright 2004-2009 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/wlan2/08:10:77:33:6c:dc
Sending on LPF/wlan2/08:10:77:33:6c:dc
Sending on Socket/fallback
DHCPDISCOVER on wlan2 to 255.255.255.255 port 67 interval 8
DHCPOFFER of 192.168.1.101 from 192.168.1.1
DHCPREQUEST of 192.168.1.101 on wlan2 to 255.255.255.255 port 67
DHCPACK of 192.168.1.101 from 192.168.1.1
bound to 192.168.1.101 — renewal in 2905 seconds.”;
7.# ifconfig 检查一下,结果如下(证明确实已经取得IP地址):
“wlan2 Link encap:以太网 硬件地址 08:10:77:33:6c:dc
inet 地址:192.168.1.101 广播:192.168.1.255 掩码:255.255.255.0
inet6 地址: fe80::a10:77ff:fe33:6cdc/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 跃点数:1
接收数据包:17 错误:0 丢弃:2359 过载:0 帧数:0
发送数据包:19 错误:0 丢弃:0 过载:0 载波:0
碰撞:0 发送队列长度:1000
接收字节:6350 (6.3 KB) 发送字节:4411 (4.4 KB)”;
8.# ping 192.168.1.1 192.168.1.1是无线路由的IP地址,ping通证明可以无线连接到热点,结果如下:
“PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=10.7 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=5.49 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=7.35 ms
64 bytes from 192.168.1.1: icmp_seq=4 ttl=64 time=5.53 ms
^C
— 192.168.1.1 ping statistics —
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 5.499/7.283/10.740/2.132 ms ”;
进阶实验,连接加密网络:
1.用无线路由建立 WPA-PSK/WPA2-PSK 方式加密的无线网络热点fover0932,密码1234567890;
2.将网卡拔出重新插上;
3.# ifconfig wlan2 up 打开无线网卡,可用ifconfig查看如下:

wlan2 Link encap:以太网 硬件地址 08:10:77:33:6c:dc
UP BROADCAST RUNNING MULTICAST MTU:1500 跃点数:1
接收数据包:0 错误:0 丢弃:0 过载:0 帧数:0
发送数据包:0 错误:0 丢弃:0 过载:0 载波:0
碰撞:0 发送队列长度:1000
接收字节:0 (0.0 B) 发送字节:0 (0.0 B)”;
4.# iwlist wlan2 scan
“wlan2 Scan completed :
Cell 01 – Address: C8:D3:A3:33:1B:FE
ESSID:”ZhuQi”
Protocol:IEEE 802.11bgn
……
Cell 04 – Address: 28:2C:B2:9E:79:D0
ESSID:”fover0932″
Protocol:IEEE 802.11bgn
Mode:Master
Frequency:2.462 GHz (Channel 11)
Encryption key:on
Bit Rates:300 Mb/s
Extra:wpa_ie=dd1a0050f20101000050f20202000050f2040050f20201000050f202
IE: WPA Version 1
Group Cipher : TKIP
Pairwise Ciphers (2) : CCMP TKIP
Authentication Suites (1) : PSK
Extra:rsn_ie=30180100000fac020200000fac04000fac020100000fac020000
IE: IEEE 802.11i/WPA2 Version 1
Group Cipher : TKIP
Pairwise Ciphers (2) : CCMP TKIP
Authentication Suites (1) : PSK
Quality=100/100 Signal level=100/100 ”;
5.# iwconfig wlan2 ap 28:2C:B2:9E:79:D0 用 # iwconfig wlan2查看如下(没有连上热点,证明该方法对加密连接无效):
“wlan2 unassociated Nickname:”
Mode:Managed Frequency=2.462 GHz Access Point: Not-Associated
Sensitivity:0/0
Retry:off RTS thr:off Fragment thr:off
Power Management:off
Link Quality:0 Signal level:0 Noise level:0
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0”;
6.# wpa_supplicant -Dwext -iwlan2 -c /etc/wpa_supplicant.conf -B 打开wpa_supplicant认证服务,用# wpa_cli -p /var/run/wpa_supplicant scan查看结果如下(说明认证服务没有打开):
ERR1:“Failed to connect to wpa_supplicant – wpa_ctrl_open: No such file or directory”
换其他目录尝试:# wpa_supplicant -D wext -i wlan2 -c /var/wpa_supplicant.conf -B ,结果如下(说明:/etc/wpa_supplicant.conf是一个空文件):
ERR2“Failed to read or parse configuration ‘/var/wpa_supplicant.conf’.”
换用wpa_cli -p /etc/wpa_supplicant scan求证,得结果如下:
ERR3“Failed to connect to wpa_supplicant – wpa_ctrl_open: Success”;
7.wpa_supplicant进程虽然没起作用,但是进程还是生成了,为了不影响后面,先把建立的进程杀死;
8.# wpa_passphrase “fover0932” “1234567890” > /etc/wpa_supplicant.conf 用指令生成配置文件,其内容如下(cat /etc/wpa_supplicant.conf):
“network={
ssid=”fover0932″
#psk=”1234567890″
psk=615f4e08e2fa27746c7480fb597227bdcd07fea052d836151fe3a041440391c1
}”;
9.重新尝试步骤6,得到结果ERR1,说明没有找到根因;
10.将配置文件作如下修改(cat /etc/wpa_supplicant.conf):
“ctrl_interface=DIR=/run/wpa_supplicant GROUP=wheel
fast_reauth = 1
ap_scan = 1
network={
ssid=”fover0932″
#psk=”1234567890″
psk=615f4e08e2fa27746c7480fb597227bdcd07fea052d836151fe3a041440391c1
}”,后报如下错误:
“# wpa_supplicant -Dwext -iwlan2 -c /etc/wpa_supplicant.conf -B
Line 2: unknown global field ‘fast_reauth = 1’.
Line 2: Invalid configuration line ‘fast_reauth = 1’.
Line 3: unknown global field ‘ap_scan = 1’.
Line 3: Invalid configuration line ‘ap_scan = 1’.
Failed to read or parse configuration ‘/etc/wpa_supplicant.conf’.”
最终修改为(cat /etc/wpa_supplicant.conf):
“ctrl_interface=DIR=/var/run/wpa_supplicant
network={
ssid=”fover0932″
#psk=”1234567890″
psk=615f4e08e2fa27746c7480fb597227bdcd07fea052d836151fe3a041440391c1
}”后,用# wpa_cli -p /var/run/wpa_supplicant scan查看结果如下:
“Selected interface ‘wlan2’
OK”,进一步用wpa_cli -p/var/run/wpa_supplicant scan_result查看结果如下:

Selected interface ‘wlan2’
bssid / frequency / signal level / flags / ssid
10:1b:54:e6:b2:fb 2427 95 [WPA-PSK-TKIP] ChinaNet-4uHB
28:2c:b2:9e:79:d0 2462 100 [WPA-PSK-TKIP+CCMP][WPA2-PSK-TKIP+CCMP] fover0932
c8:d3:a3:33:1b:fe 2412 92 [WPA-PSK-TKIP+CCMP][WPA2-PSK-TKIP+CCMP][WPS] ZhuQi
”,说明搜索OK,网卡已经能在wpa_cli指令下工作了;
11.# wpa_cli -p/var/run/wpa_supplicant remove_network 0
Selected interface ‘wlan2’
OK
# wpa_cli -p/var/run/wpa_supplicant ap_scan 1
Selected interface ‘wlan2’
OK
# wpa_cli -p/var/run/wpa_supplicant add_network
Selected interface ‘wlan2’
0
# wpa_cli -p/var/run/wpa_supplicant set_network 0 ssid ‘”fover0932″‘
Selected interface ‘wlan2’
OK
# wpa_cli -p/var/run/wpa_supplicant set_network 0 psk ‘”1234567890″‘
Selected interface ‘wlan2’
OK
# wpa_cli -p/var/run/wpa_supplicant select_network 0
Selected interface ‘wlan2’
OK
12. ifconfig
wlan2 Link encap:以太网 硬件地址 08:10:77:33:6c:dc
inet6 地址: fe80::a10:77ff:fe33:6cdc/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 跃点数:1
接收数据包:30 错误:0 丢弃:9117 过载:0 帧数:0
发送数据包:23 错误:0 丢弃:3 过载:0 载波:0
碰撞:0 发送队列长度:1000
接收字节:9098 (9.0 KB) 发送字节:2826 (2.8 KB) 
13.# dhclient wlan2
There is already a pid file /var/run/dhclient.pid with pid 5970
killed old client process, removed PID file
Internet Systems Consortium DHCP Client V3.1.3
Copyright 2004-2009 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/wlan2/08:10:77:33:6c:dc
Sending on LPF/wlan2/08:10:77:33:6c:dc
Sending on Socket/fallback
DHCPREQUEST of 192.168.1.101 on wlan2 to 255.255.255.255 port 67
DHCPACK of 192.168.1.101 from 192.168.1.1
bound to 192.168.1.101 — renewal in 3546 seconds.
14.# ping 192.168.1.1 OK,大功告成!
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.134 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.102 ms
……
— 192.168.1.1 ping statistics —
8 packets transmitted, 8 received, 0% packet loss, time 7002ms
rtt min/avg/max/mdev = 0.102/0.119/0.134/0.013 ms
实战演练:连接房东的无线热点“ZhuQi”:
1.# wpa_cli -p/var/run/wpa_supplicant ap_scan 1
Selected interface ‘wlan2’
OK
# wpa_cli -p/var/run/wpa_supplicant add_network
Selected interface ‘wlan2’
1
# wpa_cli -p/var/run/wpa_supplicant set_network 1 ssid ‘”ZhuQi”‘
Selected interface ‘wlan2’
OK
# wpa_cli -p/var/run/wpa_supplicant set_network 1 psk ‘”18789412″‘
Selected interface ‘wlan2’
OK
# wpa_cli -p/var/run/wpa_supplicant select_network 1
Selected interface ‘wlan2’
OK
2.# ifconfig
wlan2 Link encap:以太网 硬件地址 08:10:77:33:6c:dc
inet 地址:192.168.1.101 广播:192.168.1.255 掩码:255.255.255.0
inet6 地址: fe80::a10:77ff:fe33:6cdc/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 跃点数:1
接收数据包:39 错误:0 丢弃:10892 过载:0 帧数:0
发送数据包:37 错误:0 丢弃:3 过载:0 载波:0
碰撞:0 发送队列长度:1000
接收字节:10697 (10.6 KB) 发送字节:6679 (6.6 KB)
3.# dhclient wlan2
There is already a pid file /var/run/dhclient.pid with pid 4210
killed old client process, removed PID file
Internet Systems Consortium DHCP Client V3.1.3
Copyright 2004-2009 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/wlan2/08:10:77:33:6c:dc
Sending on LPF/wlan2/08:10:77:33:6c:dc
Sending on Socket/fallback
DHCPREQUEST of 192.168.1.101 on wlan2 to 255.255.255.255 port 67
DHCPNAK from 192.168.0.1
DHCPDISCOVER on wlan2 to 255.255.255.255 port 67 interval 6
DHCPOFFER of 192.168.0.106 from 192.168.0.1
DHCPREQUEST of 192.168.0.106 on wlan2 to 255.255.255.255 port 67
DHCPACK of 192.168.0.106 from 192.168.0.1
bound to 192.168.0.106 — renewal in 35829 seconds.
4.# ping 192.168.0.1
PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.
64 bytes from 192.168.0.1: icmp_seq=1 ttl=255 time=9.89 ms
64 bytes from 192.168.0.1: icmp_seq=2 ttl=255 time=6.20 ms
64 bytes from 192.168.0.1: icmp_seq=3 ttl=255 time=5.77 ms
64 bytes from 192.168.0.1: icmp_seq=4 ttl=255 time=5.77 ms
64 bytes from 192.168.0.1: icmp_seq=5 ttl=255 time=5.94 ms
^C
— 192.168.0.1 ping statistics —
5 packets transmitted, 5 received, 0% packet loss, time 4004ms
rtt min/avg/max/mdev = 5.778/6.720/9.895/1.596 ms
5.# ping baidu.com
PING baidu.com (220.181.111.86) 56(84) bytes of data.
64 bytes from 220.181.111.86: icmp_seq=1 ttl=53 time=30.5 ms
64 bytes from 220.181.111.86: icmp_seq=2 ttl=53 time=29.9 ms
^C64 bytes from 220.181.111.86: icmp_seq=3 ttl=53 time=30.2 ms
— baidu.com ping statistics —
3 packets transmitted, 3 received, 0% packet loss, time 10145ms
rtt min/avg/max/mdev = 29.900/30.201/30.501/0.283 ms

Leave a Reply