ping不同网段的脚本
#!/bin/bash
PS3="需要ping的网段:"
select ip in 192.168.20.1 192.168.130.1 172.16.1.1; do
case $ip in
192.168.20.1)
IP=(192.168.20.11 192.168.20.12 192.168.20.13)
for IP in ${IP[*]}; do
ping -c1 -i0.2 $IP > /dev/null
if [ $? -eq 0 ]; then
echo "$IP UP"
else
echo "$IP DOWN"
fi
done
;;
192.168.130.1)
for IP in {140..200}; do
timeout 0.2 ping -c1 -i0.2 192.168.130.$IP &> /dev/null
if [ $? -eq 0 ]; then
echo "192.168.130.$IP UP"
else
echo "192.168.130.$IP DOWN"
fi
done
;;
172.16.1.1)
IP=(172.16.1.24 172.16.1.25 172.16.1.26 172.16.1.34 172.16.1.41 172.16.1.42 172.16.1.43 172.16.1.44 172.16.1.49 172.16.1.50 172.16.1.51 172.16.1.52)
for ((i=0;i<${#IP[*]};i++)); do
ping -c1 -i0.2 ${IP[$i]} > /dev/null
if [ $? -eq 0 ]; then
echo "${IP[$i]} UP"
else
echo "${IP[$i]} DOWN"
fi
done
;;
*)
echo "IP 输入错误!!!"
esac
done