ping命令扫描局域网内的主机

linux: 禁ping 

vim /proc/sys/net/ipv4/icmp_echo_ignore_all 

0 代表允许 1代表禁止 


ping.sh

#!/bin/bash
for i in {2..5};
do 
 host=122.152.172.$i
 ping -c2  $host  >/dev/null
 if [ $? = 0 ]
 then    
 echo "122.152.172.$i is connected"
 else
 echo "122.152.172.$i is not connected"
 fi
done


显示结果:

[root@primary_server workspace]# ./ping.sh 
122.152.172.1 is connected
122.152.172.2 is connected
122.152.172.3 is connected
122.152.172.4 is not connected
122.152.172.5 is not connected


你可能感兴趣的:(ping命令扫描局域网内的主机)