#!/bin/sh

MAC=$1

SUBNET=10.193.108
FROM=204
TO=254

function ping_subnet()
{
#echo PING from $1 to $2
        j=$1

        while [ $j -gt $2 ]
        do
                ping -c1 $SUBNET.$j  > /dev/null
                let "j=j - 1"
        done
}


function get_ip_from_arpline()
{

        ip=` echo $2 | sed s/\(// | sed s/\)//`
}

t=$TO

while [ $t -gt $FROM ]
do

ip=` arp -an |grep -i $MAC  `
#echo IP=$ip
if [ ! -z "$ip" ]; then
	get_ip_from_arpline $ip
	echo $ip
	exit 0;
fi

let "b=t -5"
if [ $b -lt $FROM ]; then
b=$FROM
fi
ping_subnet  $t $b

let "t=t -5"

done



