我如何告诉网络管理员继续尝试重新连接到 wifi 网络永远?
我正在尝试在我无法控制的公共 WiFi 接入点使用互联网。不知道为什么,网络不是很好。连接后,它可以正常工作几个小时。但需要数十到数百次连接尝试才能最终连接。
NetworkManager[565]: <info> [1705593163.7081] device (wls6f0): Activation: starting connection 'MA:CA:DD:RE:SS_OBFUSCATED' (uuid_obfuscated)
...
NetworkManager[565]: <info> [1705593186.8841] manager: NetworkManager state is now CONNECTING
...
NetworkManager[565]: <info> [1705593186.8968] device (wls6f0): Activation: (wifi) connection 'SSID_OBFUSCATED 1' has security, and secrets exist. No new secrets needed.
...
NetworkManager[565]: <info> [1705593186.9172] device (wls6f0): supplicant interface state: disconnected -> scanning
NetworkManager[565]: <info> [1705593186.9175] device (p2p-dev-wls6f0): supplicant management interface state: disconnected -> scanning
NetworkManager[565]: <info> [1705593188.0184] device (wls6f0): supplicant interface state: scanning -> authenticating
NetworkManager[565]: <info> [1705593188.0187] device (p2p-dev-wls6f0): supplicant management interface state: scanning -> authenticating
NetworkManager[565]: <info> [1705593191.0121] device (wls6f0): supplicant interface state: authenticating -> disconnected
NetworkManager[565]: <info> [1705593191.0122] device (p2p-dev-wls6f0): supplicant management interface state: authenticating -> disconnected
NetworkManager[565]: <info> [1705593201.0140] device (wls6f0): supplicant interface state: disconnected -> scanning
NetworkManager[565]: <info> [1705593201.0144] device (p2p-dev-wls6f0): supplicant management interface state: disconnected -> scanning
NetworkManager[565]: <info> [1705593201.0592] device (wls6f0): supplicant interface state: scanning -> authenticating
NetworkManager[565]: <info> [1705593201.0594] device (p2p-dev-wls6f0): supplicant management interface state: scanning -> authenticating
NetworkManager[565]: <info> [1705593204.0095] device (wls6f0): supplicant interface state: authenticating -> disconnected
NetworkManager[565]: <info> [1705593204.0098] device (p2p-dev-wls6f0): supplicant management interface state: authenticating -> disconnected
NetworkManager[565]: <warn> [1705593212.1450] device (wls6f0): Activation: (wifi) association took too long, failing activation
不幸的是,连接失败后,NetworkManager 停止尝试。这很荒谬,因为我必须坐在电脑前等待超时,然后单击图标并手动选择 SSID。一遍又一遍。今天早上我必须这样做一个小时。计算机不应该让事情自动化吗?我刚刚把自己变成了一个点击机器人。
我想要的是能够说“连接到此”,然后走开并做午餐,知道 NetworkManager 会一遍又一遍地尝试连接,直到 [a] 连接或 [b] 时间结束。我应该能够离开计算机去吃午饭,并确保在我返回后,它会连接(目前,当我告诉它连接时,我回到我的计算机并意识到 NetworkManager 处于闲置状态,具有“放弃了”。
如何通过告诉 NetworkManager 尝试一遍又一遍(永远)连接到同一个 wifi 网络直到最终连接来自动化此过程?
答案1
我不知道如何配置网络管理器以减少懒惰并继续尝试,但我确实知道如何编写一个脚本来监视网络管理器并强制其继续工作。
#!/bin/bash
set -x
IF_DEV="wls6f0"
while true; do
date
state=$(nmcli device status | grep "${IF_DEV} " | head -n1 | awk '{print $3}')
if [[ "$state" == "disconnected" ]]; then
echo "INFO: Caught NM sitting idle. Forcing it to try to reconnect again!";
sudo nmcli device connect "${IF_DEV}"
fi
sleep 1;
echo;
done
上面的脚本是一个简单的 hack,运行时将检查接口设备(在 中设置$IF_DEV
)是否已连接。
如果其状态为disconnected
,它将告诉网络管理器尝试连接(默认为尝试连接到先前连接的网络)。
否则(例如,如果处于状态connecting
或connected
),它将等待 1 秒,然后再次检查。