[root@storage ~]# cat ping.ip
#!/bin/bash
for ip in `seq 1 255`
do
{
ping -c 2 192.168.220.$ip > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo 192.168.220.$ip >> up.txt
else
echo 192.168.220.$ip >> down.txt
fi
}&
done
wait
或者利用
#!/bin/bash
ip="192.168.220."
for i in `seq 1 254`
do
ping -c 2 $ip$i | grep -q 'ttl=' && echo "$ip$i yes"|| echo "$ip$i no"
#yes正常,no主机不存在或不正常
done