部分宽带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