判断某个网络内所有活动IP和非活动IP
要求:写一个脚本判断某个网络内所有活动的IP地址.实现脚本:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/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
脚本执行效果:
# sh ipscan.sh &
20131
# ps -ef|grep ipscan |grep -v grep
root 20131 155280 17:41 pts/1 00:00:00 sh ipscan.sh
# pwd
/root/scripts
# ls
downlistipscan.shuplist
#查看IP统计
# cat uplist |wc -l
50
# cat downlist |wc -l
203
成功扫描完毕.
页:
[1]