Friday, February 25, 2011

Compile list of IPs & PTR Records from list of IP Addresses

Simple bash script to compile a list of IP Addresses and corresponding PTR Records from a list of IP Addresses.  Make sure to give this file executable permissions (chmod +x filename).  This script will read the input file, use dig to lookup ptr records, and will output a list of the ptr records and ip address.

#!/bin/bash
inFile="input_list"
outFile="output_list"
ht=`echo -e '\011'`   # tab character
for ip in `cat $inFile`
   do
   in_addr=`echo $ip | awk -F'.' -vOSF='.' '{ print $4"."$3"."$2"."$1".in-addr.arpa" }'`   ptr=`dig PTR $in_addr | grep "IN${ht}PTR" | grep -v ';' | awk -F"$ht" -vOSF="$ht" '{ print $3 }' | sed 's/\(.*\)./\1/'`
   echo "$ptr  $ip" >> $outFile
done

No comments:

Post a Comment