Linux嵌入式开发,WIFI使用相关命令(rtl8188eu)

一、查看设备。

1、想看USB设备。

root@ms:~# lsusb
Bus 001 Device 001: ID 1d6b:0002
Bus 002 Device 001: ID 1d6b:0002
Bus 001 Device 002: ID 0424:2514
Bus 001 Device 003: ID 0bda:8179
root@ms:~#

2、查看网卡信息。

root@ms:~# ifconfig -a
can0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
          NOARP  MTU:16  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:52

eth0      Link encap:Ethernet  HWaddr 40:06:A0:F3:7D:CA
          inet addr:198.168.1.25  Bcast:198.168.1.255  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

eth1      Link encap:Ethernet  HWaddr 40:06:A0:F3:7D:CC
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

ip6tnl0   Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
          NOARP  MTU:1452  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

sit0      Link encap:IPv6-in-IPv4
          NOARP  MTU:1480  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

wlan0     Link encap:Ethernet  HWaddr 00:13:EF:80:02:5C
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

root@ms:~#

3、查看 ip。

root@ms:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
6: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
    link/ether 40:06:a0:f3:7d:ca brd ff:ff:ff:ff:ff:ff
    inet 198.168.1.25/24 brd 198.168.1.255 scope global eth0
root@ms:~#

4、查看已启动网卡。

root@ms:~# ifconfig
eth0      Link encap:Ethernet  HWaddr 40:06:A0:F3:7D:CA
          inet addr:198.168.1.25  Bcast:198.168.1.255  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

root@ms:~#

二、STA 无线终端模式。

1、拔掉网线。

2、关掉以太网。

root@ms:~# ifconfig eth0 down
root@ms:~#

3、启动无线网卡。

root@ms:~# ifconfig wlan0 up
[  246.400656] R8188EU: Firmware Version 11, SubVersion 1, Signature 0x88e1
[  246.741833] MAC Address = 00:13:ef:80:02:5c
[  246.748311] ADDRCONF(NETDEV_UP): wlan0: link is not ready
root@ms:~#

4、配置 wlan0 的 IP。

root@ms:~# ifconfig wlan0 198.168.1.35
root@ms:~#

root@ms:~# ifconfig wlan0 198.168.1.35 netmask 255.255.255.0
root@ms:~# 

5、添加缺省路由。

root@ms:~# route add default gw 198.168.1.1
root@ms:~#

6、查看是否成功添加路由。

root@ms:~# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         198.168.1.1     0.0.0.0         UG    0      0        0 wlan0
198.168.1.0     *               255.255.255.0   U     0      0        0 wlan0
root@ms:~#

7、添加缺省路由+子网掩码,并查看添加结果。

root@ms:~# route add default gw 198.168.1.1 netmask 255.255.255.0
root@ms:~# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         198.168.1.1     255.255.255.0   UG    0      0        0 wlan0
default         198.168.1.1     0.0.0.0         UG    0      0        0 wlan0
198.168.1.0     *               255.255.255.0   U     0      0        0 wlan0
root@ms:~#

8、扫描附近的无线路由器。

root@ms:~# iwlist wlan0 scan
wlan0     Scan completed :
          Cell 01 - Address: 94:E4:BA:5F:D4:04
                    ESSID:"U8"
                    Protocol:IEEE 802.11bgn
                    Mode:Master
                    Frequency:2.412 GHz (Channel 1)
                    Encryption key:on
                    Bit Rates:144 Mb/s
                    Extra:rsn_ie =30140100000fac040100000fac040100000fac020c00
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : CCMP
                        Pairwise Ciphers (1) : CCMP
                        Authentication Suites (1) : PSK
                    IE: Unknown: DD910050F204104A0001101044000102103B00010310470010123456789ABCDEF0123494E4BA5FD4041021001948756177656920546563686E6F6C6F677920436F2E2C4C74641023000B576972656C657373204150102400033132331042000531323334351054000800060050F2040001101100095753353230302D3137100800020780103C0001011049000600372A000120
                    Quality:0  Signal level:0  Noise level:0
          Cell 02 - Address: 24:FB:65:61:FE:44
                    ESSID:"CC-01"
                    Protocol:IEEE 802.11bgn
                    Mode:Master
                    Frequency:2.412 GHz (Channel 1)
                    Encryption key:on
                    Bit Rates:300 Mb/s
                    Extra:rsn_ie =30140100000fac040100000fac040100000fac020c00
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : CCMP
                        Pairwise Ciphers (1) : CCMP
                        Authentication Suites (1) : PSK
                    IE: Unknown: DD8F0050F204104A0001101044000102103B00010310470010123456789ABCDEF0123424FB6561FE441021001948756177656920546563686E6F6C6F677920436F2E2C4C74641023000B576972656C657373204150102400033132331042000531323334351054000800060050F204000110110007434433302D3130100800020780103C0001011049000600372A000120
                    Quality:0  Signal level:0  Noise level:0
          Cell 03 - Address: 94:E4:BA:5F:D4:09
                    ESSID:""
                    Protocol:IEEE 802.11bgn
                    Mode:Master
                    Frequency:2.412 GHz (Channel 1)
                    Encryption key:on
                    Bit Rates:144 Mb/s
                    Extra:rsn_ie =30140100000fac040100000fac040100000fac020c00
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : CCMP
                        Pairwise Ciphers (1) : CCMP
                        Authentication Suites (1) : PSK
                    IE: Unknown: DD230050F204104A0001101044000102100800020780103C0001011049000600372A000120
                    Quality:0  Signal level:0  Noise level:0
          Cell 04 - Address: 94:E4:BA:5F:D4:05
                    ESSID:""
                    Protocol:IEEE 802.11bgn
                    Mode:Master
                    Frequency:2.412 GHz (Channel 1)
                    Encryption key:on
                    Bit Rates:144 Mb/s
                    Extra:rsn_ie =30140100000fac040100000fac040100000fac020c00
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : CCMP
                        Pairwise Ciphers (1) : CCMP
                        Authentication Suites (1) : PSK
                    IE: Unknown: DD230050F204104A0001101044000102100800020780103C0001011049000600372A000120
                    Quality:0  Signal level:0  Noise level:0
          Cell 05 - Address: 24:FB:65:61:FE:49
                    ESSID:""
                    Protocol:IEEE 802.11bgn
                    Mode:Master
                    Frequency:2.412 GHz (Channel 1)
                    Encryption key:on
                    Bit Rates:300 Mb/s
                    Extra:rsn_ie =30140100000fac040100000fac040100000fac020c00
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : CCMP
                        Pairwise Ciphers (1) : CCMP
                        Authentication Suites (1) : PSK
                    IE: Unknown: DD230050F204104A0001101044000102100800020780103C0001011049000600372A000120
                    Quality:0  Signal level:0  Noise level:0
          Cell 06 - Address: 24:FB:65:61:FE:45
                    ESSID:""
                    Protocol:IEEE 802.11bgn
                    Mode:Master
                    Frequency:2.412 GHz (Channel 1)
                    Encryption key:on
                    Bit Rates:300 Mb/s
                    Extra:rsn_ie =30140100000fac040100000fac040100000fac020c00
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : CCMP
                        Pairwise Ciphers (1) : CCMP
                        Authentication Suites (1) : PSK
                    IE: Unknown: DD230050F204104A0001101044000102100800020780103C0001011049000600372A000120
                    Quality:0  Signal level:0  Noise level:0
          Cell 07 - Address: 92:32:4B:0A:DB:71
                    ESSID:"DIRECT-71-HP M377 LaserJet"
                    Protocol:IEEE 802.11gn
                    Mode:Master
                    Frequency:2.437 GHz (Channel 6)
                    Encryption key:on
                    Bit Rates:108 Mb/s
                    Extra:rsn_ie =30140100000fac040100000fac040100000fac020c00
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : CCMP
                        Pairwise Ciphers (1) : CCMP
                        Authentication Suites (1) : PSK
                    Quality:0  Signal level:0  Noise level:0
          Cell 08 - Address: F4:83:CD:E4:53:DE
                    ESSID:"ms"
                    Protocol:IEEE 802.11bgn
                    Mode:Master
                    Frequency:2.437 GHz (Channel 6)
                    Encryption key:on
                    Bit Rates:300 Mb/s
                    Extra:wpa_ie =dd160050f20101000050f20401000050f20401000050f202
                    IE: WPA Version 1
                        Group Cipher : CCMP
                        Pairwise Ciphers (1) : CCMP
                        Authentication Suites (1) : PSK
                    Extra:rsn_ie =30140100000fac040100000fac040100000fac020000
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : CCMP
                        Pairwise Ciphers (1) : CCMP
                        Authentication Suites (1) : PSK
                    Quality:0  Signal level:0  Noise level:0

9、修改配置文件 /etc/wpa_supplicant.conf,设置需要连接的 wifi 热点名称(ssid)及密码(psk)。

若ESSID:"ms"的PSK密码为“123456789”,执行如下。

root@ms:~# wpa_passphrase moshui "123456789" >> /etc/wpa_supplicant.conf
root@ms:~#

查看配置文件。

root@ms:~# cat /etc/wpa_supplicant.conf
#PSK/TKIP

ctrl_interface=/var/run/wpa_supplicant

network={
        ssid="test"
        scan_ssid=1
        key_mgmt=WPA-EAP WPA-PSK IEEE8021X NONE
        pairwise=TKIP CCMP
        group=CCMP TKIP WEP104 WEP40
        #psk="123456789"
        psk=e919482b4545b0e56b51add5d56921dbdf44d574d8cec7e1a7a300d703a06e85
}
network={
        ssid="moshui"
        #psk="123456789"
        psk=86cf0b544bde43fc6ed71e9b2d73f96e8d087fb59465391a8d1ba8cea344a50c
}
root@ms:~#

修改配置文件。

root@ms:~# cat /etc/wpa_supplicant.conf
#PSK/TKIP

ctrl_interface=/var/run/wpa_supplicant

network={
        ssid="test"
        scan_ssid=1
        key_mgmt=WPA-EAP WPA-PSK IEEE8021X NONE
        pairwise=TKIP CCMP
        group=CCMP TKIP WEP104 WEP40
        #psk="123456789"
        psk=e919482b4545b0e56b51add5d56921dbdf44d574d8cec7e1a7a300d703a06e85
}
network={
        ssid="moshui"
        #psk="123456789"
        psk=86cf0b544bde43fc6ed71e9b2d73f96e8d087fb59465391a8d1ba8cea344a50c
        key_mgmt=WPA-PSK
        proto=RSN WPA WPA2
        pairwise=TKIP CCMP
        group=TKIP CCMP
}
root@ms:~#

注:psk也可直接使用明码:psk="123456789"。

10、连接AP。

root@ms:~# wpa_supplicant -B -D wext -i wlan0 -c /etc/wpa_supplicant.conf
ioctl[SIOCSIWAP]: Operation not permitted
root@ms:~# [ 2877.758008] R8188EU: INFO assoc success
[ 2877.762556] ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready

root@ms:~#

root@ms:~# wpa_supplicant -D wext -i wlan0 -c /etc/wpa_supplicant.conf &
[1] 1326
root@ms:~# [ 2981.488657] ADDRCONF(NETDEV_UP): wlan0: link is not ready
ioctl[SIOCSIWAP]: Operation not permitted
Trying to associate with f4:83:cd:e4:53:de (SSID='ms' freq=2437 MHz)
[ 2982.928265] R8188EU: INFO assoc success
[ 2982.932797] ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
Associated with f4:83:cd:e4:53:de
WPA: Key negotiation completed with f4:83:cd:e4:53:de [PTK=CCMP GTK=CCMP]
CTRL-EVENT-CONNECTED - Connection to f4:83:cd:e4:53:de completed (auth) [id=1 id_str=]

root@ms:~#

注:

-D 驱动程序名称(可以是多个驱动程序:nl80211,wext)
-i 接口名称
-c 配置文件 
-B 在后台运行守护进程

11、测试网络,ping 客户 wifi 路由器的 ip。

root@ms:~# ping 198.168.1.1
PING 198.168.1.1 (198.168.1.1): 56 data bytes
64 bytes from 198.168.1.1: seq=0 ttl=64 time=2.555 ms
64 bytes from 198.168.1.1: seq=1 ttl=64 time=11.560 ms
^C
--- 198.168.1.1 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 2.555/7.057/11.560 ms
root@ms:~#

12、若 ping 不通,查看 eth0 与 wlan0 等网卡的 ip 是否在同一网段,若是,修改于不同网段,或关闭其它网卡。

13、测试网络, ping 外网。

root@ms:~# ping www.baidu.com
PING www.baidu.com (104.193.88.77): 56 data bytes
64 bytes from 104.193.88.77: seq=0 ttl=50 time=177.673 ms
64 bytes from 104.193.88.77: seq=2 ttl=50 time=177.332 ms
^C
--- www.baidu.com ping statistics ---
3 packets transmitted, 2 packets received, 33% packet loss
round-trip min/avg/max = 177.332/177.502/177.673 ms
root@ms:~#
root@ms:~# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: seq=0 ttl=105 time=349.607 ms
64 bytes from 8.8.8.8: seq=2 ttl=105 time=292.758 ms
^C
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 2 packets received, 33% packet loss
round-trip min/avg/max = 292.758/321.182/349.607 ms
root@ms:~#

14、动态获取 ip。

root@ms:~# udhcpc -i wlan0
udhcpc (v1.20.2) started
Sending discover...
Sending select for 198.168.1.100...
Lease of 198.168.1.100 obtained, lease time 7200
/etc/udhcpc.d/50default: Adding DNS 8.8.8.8
/etc/udhcpc.d/50default: Adding DNS 114.114.114.114
root@ms:~#

15、DNS修改,配置文件为 /etc/resolv.conf。

root@ms:~# cat /etc/resolv.conf
nameserver 8.8.8.8
domain bad
nameserver 8.8.8.8
nameserver 114.114.114.114
domain bad
nameserver 8.8.8.8
nameserver 114.114.114.114
root@ms:~# 

三、AP 无线热点模式。

1、重启系统 reboot。只重启WIFI网卡会自动连接,原因wpa_supplicant服务后台运行。

2、调整热点参数,修改配置文件 /etc/hostapd.conf,热点名 ssid,密码 wpa_passphrase。

##### hostapd configuration file ##############################################

interface=wlan0
ctrl_interface=/var/run/hostapd
ssid=moshui
channel=6
wpa=2
wpa_passphrase=123456789
#bridge=br0

3、启动网卡。

root@ms:~# ifconfig wlan0 up
[   82.661177] R8188EU: Firmware Version 11, SubVersion 1, Signature 0x88e1
[   83.001869] MAC Address = 00:13:ef:80:02:5c
[   83.008316] ADDRCONF(NETDEV_UP): wlan0: link is not ready
root@ms:~#

4、设置wlan0 的 IP。

root@ms:~# ifconfig wlan0 198.168.2.1
root@ms:~#

5、修改 dhcp 配置文件 /etc/udhcpd.conf。

6、开启 DHCP 服务器。

使用默认参数。

root@ms:~# dhcpd
Internet Systems Consortium DHCP Server 4.1-ESV-R9
Copyright 2004-2014 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Wrote 0 deleted host decls to leases file.
Wrote 0 new dynamic host decls to leases file.
Wrote 0 leases to leases file.

No subnet declaration for wlan0 (198.168.2.1).
** Ignoring requests on wlan0.  If this is not what
   you want, please write a subnet declaration
   in your dhcpd.conf file for the network segment
   to which interface wlan0 is attached. **


Not configured to listen on any interfaces!

If you did not get this software from ftp.isc.org, please
get the latest from ftp.isc.org and install that before
requesting help.

If you did get this software from ftp.isc.org and have not
yet read the README, please read it before requesting help.
If you intend to request help from the dhcp-bugs at isc.org
mailing list, please read the section on the README about
submitting bug reports and requests for help.

Please do not under any circumstances send requests for
help directly to the authors of this software - please
send them to the appropriate mailing list as described in
the README file.

exiting.
root@ms:~#

或使用配置文件 /etc/udhcpd.conf。

root@ms:~# udhcpd -fS /etc/udhcpd.conf &
root@ms:~#

7、开启热点。

root@ms:~# hostapd /etc/hostapd.conf &
Configuration file: /etc/hostapd.conf
Line 8: invalid WPA passphrase length 6 (expected 8..63)
WPA-PSK enabled, but PSK or passphrase is not configured.
2 errors found in configuration file '/etc/hostapd.conf'
root@ms:~#

未成功,原因在于密码长度不够,重新修改密码后,如下。

root@ms:~# hostapd /etc/hostapd.conf -B
Configuration file: /etc/hostapd.conf
drv->ifindex=3
l2_sock_recv==l2_sock_xmit=0x0x65630
Failed to request a scan of neighboring BSSes
+rtl871x_sta_deauth_ops, ff:ff:ff:ff:ff:ff is deauth, reason=2
rtl871x_set_key_ops
rtl871x_set_key_ops
rtl871x_set_key_ops
rtl871x_set_key_ops
Using interface wlan0 with hwaddr 00:13:ef:80:02:5c and ssid 'moshui'
rtl871x_set_beacon_ops
[  366.731881] R8188EU: INFO assoc success
rtl871x_set_hidden_ssid ignore_broadcast_ssid:0, moshui,6
rtl871x_set_acl
rtl871x_set_wps_assoc_resp_ie
rtl871x_set_wps_beacon_ie
rtl871x_set_wps_probe_resp_ie
rtl871x_set_key_ops
rtl871x_set_beacon_ops
rtl871x_set_hidden_ssid ignore_broadcast_ssid:0, moshui,6
rtl871x_set_acl
root@ms:~#

8、PC端连接后自动分配 IP。

root@ms:~# [  429.475030] R8188EU: INFO ap recv disassoc reason code(8) sta:ec:5c:68:78:60:ad
[  436.577129] R8188EU: INFO ap recv disassoc reason code(8) sta:ec:5c:68:78:60:ad

root@ms:~#

9、测试。

root@ms:~# ping 198.168.2.200
PING 198.168.2.200 (198.168.2.200): 56 data bytes
64 bytes from 198.168.2.200: seq=0 ttl=128 time=3.912 ms
64 bytes from 198.168.2.200: seq=1 ttl=128 time=1.509 ms

10、断开PC端其它网络。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

寞水

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值