直接贴代码,由于Wordpress编辑器的问题,请自行转义>为>。另,为排版需要,部分行是被迫换行的,请注意。
#!/bin/bash
# test default gateway access
gw=`ping -q -w 1 -c 1 \`ip r | grep default | cut -d ' ' -f 3\` > /dev/null
echo "ok" || echo "failed"`
if [ $gw = "ok" ]; then
echo "Gateway is ready"
else
echo "Gateway is unreachable, check your internet connection!"
exit 1
fi
iptunnel=`ifconfig | grep sit1`
if [ -n "$iptunnel" ]; then
ip tunnel del sit1
fi
addr4=`ifconfig wlan0 | grep "inet addr" | cut -f 2 -d ":" | cut -f 1 -d " "`
ip tunnel add sit1 mode sit remote 211.68.71.43 local $addr4
ifconfig sit1 up
ifconfig sit1 add 2001:da8:215:5200:0:5efe:$addr4/64
iproute=`route -A inet6 | grep "2001:da8:215:5200"`
if [ -n "$iproute" ]; then
ip route add ::/0 via 2001:da8:215:5200::1 metric 1
fi
# test ipv6 connect
ipv6_srv=(
[0]="ipv6.google.com"
[1]="www.huangwei.me"
[2]="he.net"
)
for srv in ${ipv6_srv[@]}; do
ping6 -q -w 1 -c 1 $srv | grep "1 received" > /dev/null
&& echo "$srv is ready" || echo "$srv is failed"
done