该脚本是用来扫描网段内存活主机,并自动保存其mac地址。
#/bin/bash
#扫描内网所有主机,获取MAC地址ETH=$(ifconfig | grep "eth" | awk '{print $1}')
NET="192.168.0"for((i=1;i<255;i++))
dores=$(arping -c 2 -w 1 $NET.$i -I $ETH | grep "reply from" | awk '{print $4","$5}')#echo $restest -z $resif [ $? -eq 1 ]thenecho "$res" >> mac.txtecho "$NET.$i的MAC地址已写入mac.txt"elseecho "$NET.$i is down"fi
done
echo "finish"