正如我的帖子标题所说,我有一个脚本(如下)运行到负责启动无线连接(WPA2)的服务中,如果不能,它会启动接入点模式。
#!/bin/bash
wget -q --tries=10 --timeout=20 --spider http://google.com
if [[ $? -eq 0 ]]; then
echo "Connected"
else
echo "Try to get a connection"
pkill wpa_supplicant
systemctl stop dnsmasq
systemctl stop hostapd
#systemctl disable dnsmasq
systemctl disable hostapd
ifdown wlan0
ifup wlan0=wlan_user
wget -q --tries=10 --timeout=20 --spider http://google.com
if [[ $? -eq 0 ]]; then
echo "Connected"
else
echo "Access point mode"
ifdown wlan0
systemctl restart dnsmasq
systemctl restart hostapd
ifconfig wlan0 up
ifconfig wlan0 10.0.0.1/24
#iptables -t nat -F
#iptables -F
#iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
#iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
#echo '1' > /proc/sys/net/ipv4/ip_forward
fi
fi
cp /etc/network/interfaces /tmp/interfaces
为了测试它是否有效,我在终端中启动它,它运行良好,但当它由我的服务启动时,它会连接但立即断开连接,并显示“获取取消身份验证的本地选择(原因:3 = DEAUTH_LEAVING)”。注意:它在连接到非 WPA 无线连接时有效