Router OS 监测 Google 204 状态,不通则切换 DNS 为 119.9.9.9,通则为 10.0.0.1
要实现这个功能,您可以使用以下步骤:
-
在路由器上安装支持自定义脚本的路由器操作系统(例如 OpenWrt)。
-
创建一个脚本来监测 Google 生成的 204 状态。您可以使用
curl命令来检测状态码。以下是一个示例脚本:
#!/bin/sh
response=$(curl -s -o /dev/null -w '%{http_code}' https://www.google.com/generate_204)
if [ '$response' != '204' ]; then
# 切换DNS为119.9.9.9
uci set network.wan.dns='119.9.9.9'
uci commit network
/etc/init.d/network restart
else
# 切换DNS为10.0.0.1
uci set network.wan.dns='10.0.0.1'
uci commit network
/etc/init.d/network restart
fi
-
将脚本保存为
google_check.sh,并将其上传到路由器上的适当位置(例如/root/google_check.sh)。 -
授予脚本执行权限:
chmod +x /root/google_check.sh
- 使用 cron 任务定期运行脚本。打开 cron 编辑器:
crontab -e
- 在 cron 文件中添加以下行来定期运行脚本(例如每 5 分钟运行一次):
*/5 * * * * /root/google_check.sh
- 保存并关闭 cron 编辑器。
现在,路由器将每 5 分钟运行脚本,检测 Google 生成的 204 状态。如果状态码不是 204,则切换 DNS 为 119.9.9.9,否则切换为 10.0.0.1。请根据您的路由器操作系统和网络配置进行必要的调整。
原文地址: https://www.cveoy.top/t/topic/bAWP 著作权归作者所有。请勿转载和采集!