用shell统计局域网内的以用IP+MAC地址和未使用的IP

最近公司震动内网网络,需要收集一下那些IP没有用,网上搜了这个一个脚本,给大家分享一下:
#!/bin/bash
IPaddr=10.20.221.
IPFILE=/root/arping.txt
UPIPaddr=/tmp/ipup.txt
DOWNIPaddr=/tmp/ipdown.txt
>$IPFILE
touch $DOWNIPaddr
touch $UPIPaddr
touch $IPFILE
for IP in {1..254}
do
arping -c 1 $IPaddr$IP >>$IPFILE
done
echo UPIPADDR
echo " 

IPADDR                      MAC ";  cat $IPFILE  | grep reply |awk '{print $4"      "$5}' |awk -F"[" '{print $1" "$2}' | awk -F"]" '{print $1"  "$2}' | column -t >$UPIPaddr
echo DOWNIPADDR
IPTMP=/tmp/ip.txt
IPTMP2=/tmp/ip2.txt
grep -v ^'[S|R]' $IPFILE |awk -FARPING '{print $2}'|awk -Ffrom '{print $1}' |column -t >$IPTMP
grep -v ^'[S|R]' $IPFILE |awk -F"Unicast reply from" '{print $2}'|awk '{print $1}'| uniq -c |awk '{print $2}' |uniq -c |awk '{print $2}'|column -t >$IPTMP2
cat $IPTMP $IPTMP2 | sort -t "." -k4,4n |uniq -u  >$DOWNIPaddr
VL=` wc -l $UPIPaddr |awk '{print $1}'`
VL2=`wc -l $DOWNIPaddr |awk '{print $1}'`
cat $UPIPaddr
echo 目前有$VL台主机为活动状态
cat $DOWNIPaddr | paste -s
echo 目前有$VL2个可用IP地址


[root@localhost ~]# sh test.sh
UPIPADDR
  IPADDR                      MAC
DOWNIPADDR
10.20.221.6      00:05:1E:E6:64:91
10.20.221.7      00:05:1E:ED:2D:C6
10.20.221.9      00:25:9E:D2:B0:24
10.20.221.10    00:25:9E:D2:B0:90
10.20.221.11    00:10:5C:FA:F0:5A
10.20.221.12    00:50:56:88:55:53
10.20.221.13    00:50:56:88:5A:4A
10.20.221.14    00:10:5C:FA:F0:6C
10.20.221.238  00:50:56:7E:BA:29
10.20.221.239  00:50:56:75:97:B4
10.20.221.244  3C:E5:A6:B1:7F:5D
10.20.221.252  98:4B:E1:6F:F2:B4
目前有138台主机为活动状态
10.20.221.1        10.20.221.2        10.20.221.3        10.20.221.4        10.20.221.5        10.20.221.8        10.20.221.22            10.20.221.25      10.20.221.32      10.20.221.33      10.20.221.34      10.20.221.40      10.20.221.48            10.20.221.49      10.20.221.50      10.20.221.51      10.20.221.52      10.20.221.53      10.20.221.54            10.20.221.55      10.20.221.56      10.20.221.57      10.20.221.58      10.20.221.59      10.20.221.60            10.20.221.61      10.20.221.62      10.20.221.63      10.20.221.64      10.20.221.65      10.20.221.66            10.20.221.67      10.20.221.68      10.20.221.69      10.20.221.70      10.20.221.71      10.20.221.72            10.20.221.73      10.20.221.74      10.20.221.75      10.20.221.76      10.20.221.77      10.20.221.78            10.20.221.79      10.20.221.80      10.20.221.83      10.20.221.84      10.20.221.100    10.20.221.108          10.20.221.109    10.20.221.110    10.20.221.113    10.20.221.114    10.20.221.120    10.20.221.122          10.20.221.123    10.20.221.125    10.20.221.138    10.20.221.139    10.20.221.142    10.20.221.143          10.20.221.144    10.20.221.145    10.20.221.146    10.20.221.147    10.20.221.148    10.20.221.149          10.20.221.151    10.20.221.153    10.20.221.154    10.20.221.155    10.20.221.156   
目前有118个可用IP地址
[root@localhost ~]#

你可能感兴趣的:(shell,IP,休闲,统计局域网,IP+MAC地址)