#!/bin/bash
echo > /1/ping.txt
read -p "输入起始ip地址:" startip
read -p "输入结束ip地址:" stopip
a=`echo $startip | awk -F. '{print $1}'`
b=`echo $startip | awk -F. '{print $2}'`
c=`echo $startip | awk -F. '{print $3}'`
d=`echo $startip | awk -F. '{print $4}'`
sa=`echo $stopip | awk -F. '{print $4}'`
while [ $d -le $sa ]
do
x=`echo $a.$b.$c.$d`
ping -c 2 -i 0.2 -w 3 $x &> /dev/null
if [ $? -eq 0 ]
then
echo $x >> /1/ping.txt
else
echo "$x:该地址不可达"
fi
let d++
done
for ip in `cat /1/ping.txt`
do
mac=`arp -n $ip | grep $ip | awk '{print $3}'`
echo "$ip 的主机地址为$mac"
done
~