判断ping通网段所有的ip

#!/bin/bash
# Ping all the PC in a network segment
n=0
for  (( i=1; i<255; i++ )) do ping -c1 -w1 $1.$i > /dev/null
	if [ $? -eq 0 ]
	then 
		echo "The $1.$i is Online"
		n=$[$n+1]
	else
		:
	fi
done
echo "There is $n user "
pi@bananapi ~/shell $ cat checkip.sh
#!/bin/bash
for ip in 192.168.0.{1..255}
do
 ping $ip -c 2 &> /dev/null
 if [ $? -eq 0 ];
 then
 echo $ip is alive
 else
 echo $ip is not connect
 fi
done
pi@bananapi ~/shell $ cat checkip2.sh
#!/bin/bash
for ip in 192.168.0.{1..255}
do
 (
 ping $ip -c 2 &> /dev/null
 if [ $? -eq 0 ];
 then
 echo $ip is alive
 else
 echo $ip is not connect
 fi
 )&
done
wait
pi@bananapi ~/shell $
    A+
发布日期:2016年09月13日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: