comparison forward <-> corresponding reverse

Waltner, Steve swaltner at lsil.com
Mon Sep 10 19:55:37 UTC 2001


Folks need to take a little time looking at a problem before giving up. Here
is a script I hacked together in about 15 minutes.

Steve

[bart:~] swaltner% chkrevaddrs lsil.com @lsi.lsil.com
dhcp-172-22-191-1.lsil.com (172.22.191.1) - reverse name
(ICTT20TESTLT.dhcp.lsil.com)
dhcp-172-22-191-86.lsil.com (172.22.191.86) - no associated PTR record
[bart:~] swaltner% cat chkrevaddrs
#!/usr/bin/perl
#
use Net::DNS;

if (@ARGV != "2") {
  &usage;
  exit;
}
# Is argument 1 or 2 the DNS server we are supposed to query
if ($ARGV[0] =~ /^@/) {
  ($dnsServer = $ARGV[0]) =~ s/^@//;
  $dnsDomain = $ARGV[1];
} else {
  ($dnsServer = $ARGV[1]) =~ s/^@//;
  $dnsDomain = $ARGV[0];
}

sub usage {
  print "usage: chkrevaddrs @<DNS-server> <DNS-domain>\n";
}

$res = new Net::DNS::Resolver;

# Setup and complete the zone transfer
$res->nameservers("$dnsServer");
$res->tcp_timeout(10);

@zone = $res->axfr("$dnsDomain");

if (@zone) {
  $res = new Net::DNS::Resolver;

  foreach $rr (@zone) {
    # We only care about A records
    if ($rr->type eq "A") {
      $name = $rr->name;
      $ipAddr = $rr->rdatastr;
      $revAddr = &IPtoArpaAddr($ipAddr);

      $query = ($res->query ("$revAddr", "PTR"));
      if ($query) {
        $answer = ($query->answer)[0];
        $str = $answer->rdatastr;
        $str =~ s/\.$//;
        if ($name ne $str) {
          print "$name ($ipAddr) - reverse name ($str)\n";
        }
      } else {
        print "$name ($ipAddr) - no associated PTR record\n";
      }
    }
  }
}

sub IPtoArpaAddr {
  #             
  # Convert an IP address (1.2.3.4) into Reverse DNS Entry
(4.3.2.1.in-addr.arpa);
  #
  local ($reverseDomain, $reverseAddr); 

  $reverseDomain = ".in-addr.arpa";

  $reverseAddr = join (".", (split(/\./, $_[0]))[3,2,1,0]) . $reverseDomain;

  return ($reverseAddr);
}
[bart:~] swaltner% 

> ----------
> From: 	Bjoern Krueger
> Sent: 	Monday, September 10, 2001 12:39 PM
> To: 	comp-protocols-dns-bind at moderators.isc.org
> Subject: 	comparison forward <-> corresponding reverse
> 
> Our bind 8 is working with alot of zonesfiles (> 150).
> We want to check if there are hosts which have A records (well, a A 
> record), but no corresponding RR.
> 
> Is there any tool capable of doing an automatic comparison, e.g. by 
> browsing the forward files in named.conf and checking if the names 
> resolve reverse (have an RR)?
> 
> Thanks for any reply.
> Bjoern
> -- 
> Bjoern Krueger
> dvdman at web dot de
> Please reply ONLY to this newsgroup, thanks.
> 
> 




More information about the bind-users mailing list