openwrt自动检测宽带外网是否可访问

openwrt自动检测宽带外网是否可访问

部分宽带ip无法访问外网,这是运营商的问题,自动检测并重启宽带

#!/bin/sh

# Script to check connectivity and restart network if condition met
# Ping www.baidu.com 3 times successfully but 8.8.8.8 fails 3 times

# Function to check if ping succeeds (returns 0 if at least one packet received)
ping_check() {
    ping -c 10 -W 5 "$1" >/dev/null 2>&1
    return $?
}

# Check www.baidu.com
if ping_check "www.baidu.com"; then
    # If baidu succeeds, check 8.8.8.8
    if ! ping_check "8.8.8.8"; then
        # Condition met: restart network interface (assuming wan, adjust if needed)
        logger "Network restarted due to baidu ping success but 8.8.8.8 failure"
        /etc/init.d/network restart
    fi
fi

Copyright: 采用 知识共享署名4.0 国际许可协议进行许可

Links: https://zwc365.com/2026/04/01/openwrt-zi-dong-jian-ce-kuan-dai-wai-wang-shi-fou-ke-fang-wen

Buy me a cup of coffee ☕.