判断某个网络内所有活动IP和非活动IP


要求:写一个脚本判断某个网络内所有活动的IP地址.


实现脚本:

#!/bin/bash
#script_name: ipscan.sh

file1=/root/scripts/uplist
file2=/root/scripts/downlist

if [  -e $file1 ]
then
    rm -rf $file1
fi


if [  -e $file2 ]
then
    rm -rf $file2
fi


for ((i=2;i<=254;i++))
do
        /bin/ping -c 1 192.168.3.$i >>/dev/null
        if [ $? -eq 0 ]
        then
                echo "192.168.3.$i is alive" >> /root/scripts/uplist
        else
                echo "192.168.3.$i is not alive" >> /root/scripts/downlist
        fi
done


脚本执行效果:


[root@zabbix scripts]# sh ipscan.sh &

[1] 20131

[root@zabbix scripts]# ps -ef|grep ipscan |grep -v grep

root     20131 15528  0 17:41 pts/1    00:00:00 sh ipscan.sh

[root@zabbix scripts]# pwd

/root/scripts

[root@zabbix scripts]# ls

downlist  ipscan.sh  uplist

#查看IP统计

[root@zabbix scripts]# cat uplist |wc -l

50

[root@zabbix scripts]# cat downlist |wc -l

203



成功扫描完毕.


你可能感兴趣的:(网络,IP地址)