启动wifi服务
connmanctl disable wifi
connmanctl enable wifi
ifconfig wlan0 down
ifconfig wlan0 up
wpa_supplicant包含两个主要的可执行工具:wpa_supplicant和wpa_cli。
wpa_supplicant是核心程序,它和wpa_cli的关系就是服务和客户端的关系:后台运行wpa_supplicant,使用wpa_cli来搜索、设置、和连接网络。
大部分情况下编辑好配置文件,运行wpa_supplicant 就可以连通网络了,
创建一个 wpa_supplicant.conf
可以
echo "update_config=1" > /tmp/ema_wpa_supplicant.conf
echo "ctrl_interface=/var/run/wpa_supplicant" >> /tmp/ema_wpa_supplicant.conf
vi /tmp/wpa_supplicant.conf
ctrl_interface=/var/run/wpa_supplicant
update_config=1
其中,update_config=1使能配置更改。
关闭 wpa_supplicant
kill -9 `pgrep wpa_supplicant`
wpa_supplicant 命令如下
usage:
wpa_supplicant [-BddhKLqqtuvW] [-P<pid file>] [-g<global ctrl>] \
[-G<group>] \
-i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] [-p<driver_param>] \
[-b<br_ifname>] [-e<entropy file>] [-f<debug file>] \
[-o<override driver>] [-O<override ctrl>] \
[-N -i<ifname> -c<conf> [-C<ctrl>] [-D<driver>] \
[-m<P2P Device config file>] \
[-p<driver_param>] [-b<br_ifname>] [-I<config file>] ...]
drivers:
nl80211 = Linux nl80211/cfg80211
wext = Linux wireless extensions (generic)
wired = Wired Ethernet 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)
-d = increase debugging verbosity (-dd even more)
-D = driver name (can be multiple drivers: nl80211,wext)
-e = entropy file
-f = log output to debug file instead of stdout
-g = global ctrl_interface
-G = global ctrl_interface group
-h = show this help text
-i = interface name
-I = additional configuration file
-K = include keys (passwords, etc.) in debug output
-L = show license (BSD)
-m = Configuration file for the P2P Device interface
-M = start describing new matching interface
-N = start describing new interface
-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)
-t = include timestamp in debug messages
-u = enable DBus control interface
-v = show version
-W = wait for a control interface monitor before starting
example:
wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wpa_supplicant.conf
其中最常用的为:
-i 指定端口
-c 指定配置文件
-D 指定使用的wifi驱动
我们这里只指定端口和配置文件,驱动使用默认的。
查看网卡端口 ifconfig
使用以下命令配置
wpa_supplicant -i wlan0 -D nl80211 -c/tmp/ema_wpa_supplicant.conf -B
wpa_cli -i wlan0 scan 扫描
sleep 10
wpa_cli -i wlan0 scan_results | grep "$2"
这样就测试WiFi成功