要求:写一个脚本判断某个网络内所有活动的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
|
脚本执行效果:
[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
本文转自 marbury 51CTO博客,原文链接:http://blog.51cto.com/magic3/1438515