临时检测局域网中未使用的IP地址
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
#!/bin/bash
echo
"检测局域网中未使用的IP地址2015"
echo
""
processbar() {
local
current=$1;
local
total=$2;
local
maxlen=80;
local
barlen=66;
local
perclen=14;
local
format
=
"%-${barlen}s%$((maxlen-barlen))s"
local
perc=
"[$current/$total]"
local
progress=$((current*barlen
/total
))
local
prog=$(
for
i
in
`
seq
0 $progress`;
do
printf
'#'
;
done
)
printf
"\r$format"
$prog $perc
}
for
i
in
`
seq
1 254`;
do
processbar $(($i*100
/254
)) 100
/usr/bin/arping
-I eth0 -c 1 192.168.10.$i |
grep
-B 2
"Received 0"
|
head
-1 >> mac$(
date
+%Y%m%d).txt ;
done
|
程序中循环进度条参考自:http://blog.csdn.net/wxqee/article/details/38332141
或者使用
1
2
3
4
5
6
7
8
9
10
|
#!/bin/bash
echo
查找未使用的IP地址,通过检测MAC,来找,如果没有开机,无法找到!
for
(( i=1 ; i<254; i++ ))
do
/usr/bin/arping
-I eth0 -c 1 192.168.0.$i |
grep
-B 2
"Received 0"
|
grep
"192.168.0."
>>mac$(
date
+%Y%m%d).txt ;
# sleep 3
echo
-e
"--> $(($i*100/254)) % \c "
done
echo
100%执行完毕,已输出到当前目录下的mac$(
date
+%Y%m%d).txt文件,请查看!
|
本文转自 lcpljc 51CTO博客,原文链接:http://blog.51cto.com/lcpljc/1677375,如需转载请自行联系原作者