测试能否连通外网:
pingres=`ping -c 1 baidu.com | sed -n '/64 bytes from/p'`
if [ -z "$pingres" ]
then
echo "network error"
exit 1
fi
查看局域网内不可达的ip,find_unreachable_ip_in_lan.sh:
#!/bin/sh
if [ "$1" != "" ]; then
lan_prefix=$1
else
lan_prefix="10.10.10"
fi
for ((i=2; i<255; i+=1))
do
ip="$lan_prefix.$i"
exists=`ping -c 2 $ip | grep -i Unreachable | wc -l`
if [ "$exists" != "0" ]; then
echo $ip
fi
done
--end--