#! /bin/bash

                     


if [ "$1" == "" ]; then
  echo  "$0 (XX-00-XX-00-XX-00) "
  exit 1
fi 




RV=/var/www/maincp/var
RL=$RV/mac46.tmo
RT=$RV/mac46.tmp
RSW=$RV/mac46.sw

MAC1=$1

touch $RL 

/usr/local/sbin/chilli_query list >$RL


/bin/egrep -i -c -e $MAC1 $RL > $RSW



/bin/egrep -i -e $MAC1 $RL  | tail -n1 > $RT




SW2=`cat $RSW`

if [ "$SW2" == "1" ]
then


FI=`cat $RT`

GH=($FI)

let B=1

for j in "${GH[@]}"
do

if [ $B -eq 2 ]
then

IP=$j

fi

let B=B+1

done

rm -f $RL
rm -f $RT
rm -f $RSW

/bin/echo "$IP"


rm -f $RL
rm -f $RT
rm -f $RSW




else





RV=/var/www/maincp/var
RL1=$RV/mac45.log
RT1=$RV/mac45.tmp
RT2=$RV/mac452.tmp
RSW1=$RV/mac45.sw

MAC1=$1


/usr/local/sbin/chilli_query list >$RL1

/bin/egrep -i -e $MAC1 $RL1  | tail -n1 > $RT1

let B=1

RT2=($RT1)


for a in "${RT2[@]}"
do

if [ $B -eq 2 ]
then

IP="$a"

fi

let B=B+1

done



if [ -z $IP ];
then

MSG="NO PAD"

BUS="MAC=$MAC1"

#/bin/egrep -i -e $BUS /var/log/syslog.1 >$RT2
/bin/grep -i -e $BUS /var/log/syslog | tail -n1 > $RT


FI=`cat $RT`

FI2=($FI)

H=1


for j in "${FI2[@]}"
do

if [ $H -eq 9 ]
then

IP="$j"

fi

let H=H+1

done




fi


rm -f $RL1
rm -f $RT1
rm -f $RSW1
rm -f $RT2
rm -f $RT

echo $IP >$RT

IP=`cut -b 4-21 $RT`

echo $IP

 
fi




rm -f $RL
rm -f $RT
rm -f $RSW

rm -f $RL1
rm -f $RT1
rm -f $RSW1











