Skip to content

Instantly share code, notes, and snippets.

@hanxi
Last active December 17, 2020 01:50
Show Gist options
  • Save hanxi/153bccdba9ae5f90ab82338157455417 to your computer and use it in GitHub Desktop.
Save hanxi/153bccdba9ae5f90ab82338157455417 to your computer and use it in GitHub Desktop.
检查网络并重连 wan 口,检测多个 url
#!/bin/sh
# filename: /root/chk_net_redail.sh
# 4=network error/refused/timeout/dns err/
# need "opkg install wget ca-bundle"
log()
{
#echo $*
logger -t redail $*
}
check_network(){
ping -c 3 $1 1>/dev/null 2>/dev/null
return $?
}
count=0
HOSTS='www.baidu.com www.163.com www.qq.com www.sogou.com 223.5.5.5 223.6.6.6 8.8.8.8 8.8.4.4 114.114.114.114'
for host in $HOSTS; do
log will check $host
if check_network $host; then
break
else
count=$((count+1))
fi
done
HOST_CNT=$(echo $HOSTS|wc -w)
if [ $count -ge $HOST_CNT ]; then
log will redail
ifdown wan; sleep 5; ifup wan
else
log check network ok
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment