Archive for November, 2010

It’s always handy to have a script to create the reverse lookup records from a forward lookup zone file. So here its goes…

#!/bin/sh
#@Author Daysen — daysenv@gmail.com

#———–
>rev

cp /var/lib/named/master/de.daysen.com.hosts fwd
sed -e ‘/^;/d’ fwd | sed -e ‘/^$/d’ > f1

while read line
do
RD_=`echo $line | awk ‘{print $3}’`
IN_=`echo $line | awk ‘{print $2}’`

if [ “$IN_” = “IN” ] && [ “$RD_” != “SOA” ]
then

if [ “$RD_” != “SRV” ]
then
if [ “$RD_” = “CNAME” ] || [ “$RD_” = “NS” ]
then
CN_=`echo $line | awk ‘{print $4}’`
if [ “$RD_” = “NS” ]
then
c=`nslookup $CN_ | grep -v “127.0.0.1” | grep “Address” | awk ‘{print $2}’ | awk -F . ‘{print $2″.”$1}’`
a=”$c.in-addr.arpa. IN NS     “
b=`echo $line | awk ‘{print $4}’`
else

c=`nslookup $CN_ | grep -v “127.0.0.1” | grep “Address” | awk ‘{print $2}’`
a=`echo $c | awk -F . ‘{print $4″.”$3″.”$2″.”$1″.in-addr.arpa.        IN        PTR     “}’`
b=`echo $line | awk ‘{print $1}’`
fi
else

c=`echo $line | awk ‘{print $4}’`
a=`echo $c | awk -F . ‘{print $4″.”$3″.”$2″.”$1″.in-addr.arpa.        IN        PTR     “}’`
b=`echo $line | awk ‘{print $1}’`
fi

echo $a”        “$b >> rev
sort -k3,4 rev > f2
mv f2 rev
fi
fi

done < f1

rm -f f1

Advertisements