原理就是通过icmp协议的type 8 ,既ping来时实现,因此呢 对方必须没有屏蔽此协议,否则探测的结果可能就会有失误。 #!/bin/bash PING(){ ping -c 1 -w 2 $1>/dev/null 2>&1 if [ $? -eq 0 ];then echo -e "\t Test $1 Successfully..." echo $1>>/mnt/Ip_List.log let Num++ else echo -e "\t Test $1 Failed..." fi } Num=0 for ((i=1;i<=254;i++)) do PING 192.168.20.${i} done echo "IP List:" echo ++++++++++++++ cat /mnt/Ip_List.log echo ++++++++++++++ echo "The number of IP : $Num" rm -fr /mnt/Ip_List.log
演示: [iyunv@localhost Others]# sh b Test 192.168.20.1 Successfully... Test 192.168.20.2 Failed... Test 192.168.20.3 Failed... Test 192.168.20.4 Failed... Test 192.168.20.5 Failed... Test 192.168.20.6 Failed... Test 192.168.20.7 Failed... Test 192.168.20.8 Failed... Test 192.168.20.9 Failed... Test 192.168.20.10 Successfully... Test 192.168.20.11 Failed... Test 192.168.20.12 Failed... .. .. Test 192.168.20.254 Failed... IP List: ++++++++++++++ 192.168.20.1 192.168.20.10 192.168.20.48 192.168.20.68 192.168.20.99 192.168.20.100 192.168.20.113 192.168.20.122 192.168.20.126 192.168.20.133 192.168.20.143 ++++++++++++++ The number of IP : 11 #提示下,一直按住ctrl + c,是能加快检测速度的!!! #顺便提一句,我的LingYi软件004版中就有此项小功能,呵呵,而且功能更强大 #不但能检测用户输入ip的格式是否正确,而且还能自动检测网卡ip及 #所属网段,从而自动探测在线ip
|