#!/usr/bin/perl -w # checkDNS.pl - A forward & reverse DNS query script # # 25 May 2005 # Christopher Juckins # # Script checks hosts in a particular IP address range for DNS entries. # It's a quick and dirty way to see what IP addresses are associated # with DNS entries on your network. # # Script asks user for the following input: # Network (Example: 205.165.5) # Begin host to check (Example: 1) # End host to check (Example: 254) # DNS Server to use for lookups (Example: 205.165.5.242) # # Script runs, doing a 'host' lookup on each address in the range. # If a host is found, it is then checked for forward (normal) DNS. # # If nothing is returned for a particular entry, it is noted and # the forward lookup will not run for that entry. # Duplicate entries are also returned for the reverse checks. # # The output prints to screen and also to /tmp/checkDNS.txt print "Enter network in form XXX.XXX.XXX -->"; $NETWORK = ; chomp($NETWORK); print "Enter start range of IP to scan -->"; $BEGIN= ; chomp($BEGIN); print "Enter end range of IP to scan -->"; $END = ; chomp($END); print "Enter DNS server IP address to use for checking -->"; $SERVER = ; chomp($SERVER); # Open file for output open (OUTPUT, ">/tmp/checkDNS.txt"); print "\nReverse DNS lookup follows...\n"; for ($ip = $BEGIN; $ip <= $END; $ip++) { # Create host to check $host = "$NETWORK." . "$ip"; # Create query for 'host' command $query = "$host" . " $SERVER"; # Store info that is returned from the query $dns = `host $query`; # Split apart the multiple lines that get returned @dns = split(/\n/, $dns); # Only get the lines that have data we want (domain name pointer) foreach $entry(@dns) { if ($entry =~ /domain\sname\spointer/) { @entry = split(/\s/, $entry); # Get index value for the last array element $last = $#entry; # Remove annoying trailing period (.) if ($entry[$last] =~ s/\.$//) { } print OUTPUT "$host, "."$entry[$last]\n"; print "$host, "."$entry[$last]\n"; # Set up array for forward zone checking push(@forward,$entry[$last]); } if ($entry =~ /not\sfound/) { print OUTPUT "$host, NOT_IN_USE\n"; print "$host, NOT_IN_USE\n"; } } } # Now do forward lookup print "\nForward DNS lookup follows...\n"; foreach $entry(@forward) { $dns = `host $entry`; # Clean up printed output if ($dns =~ s/\shas\saddress/,/) { } print OUTPUT "$dns"; print "$dns"; }