#!/usr/bin/perl -w # ------------------------------------------------------------------------------ # "THE BEER-WARE LICENSE" (Revision 42): # wrote this file. As long as you retain this notice you # can do whatever you want with this stuff. If we meet some day, and you think # this stuff is worth it, you can buy me a beer in return. Anders Giversen # ------------------------------------------------------------------------------ use strict; use Net::DNS; my $DEBUG = 0; if (! @ARGV) { print "$0: Use $0 domain\n"; exit 1; } foreach my $domain (@ARGV) { my $res = new Net::DNS::Resolver; $res->defnames(0); # Get name servers my $ns_req = $res->query($domain, "NS"); unless (defined($ns_req) && ($ns_req->header->ancount > 0)) { print "$domain: No name servers found - " . $res->errorstring . "\n"; next; } my @nameservers = grep { $_->type eq "NS" } $ns_req->answer; my $serial = 0; my %SOA = (); my $i = 0; # Set the recursion flag $res->recurse(0); foreach my $nsserver (@nameservers) { my $ns = $nsserver->nsdname; print "Name server: $ns\n" if $DEBUG; # Specify which name server to use unless ($res->nameservers($ns)) { print "ERROR ($ns): Can't find address of name server - " . $res->errorstring . "\n"; next; } # Get SOA record my $soa_req = $res->send($domain, "SOA"); unless (defined($soa_req)) { print "ERROR ($ns): No SOA record found for $domain - " . $res->errorstring . "\n"; next; } # Name server authoritative? unless ($soa_req->header->aa) { print "ERROR ($ns): Is not authoritative for $domain\n"; next; } # Check answer unless ($soa_req->header->ancount == 1) { print "ERROR ($ns): Expected 1 answer, got " . $soa_req->header->ancount . " ($domain)\n"; next; } # SOA record? unless (($soa_req->answer)[0]->type eq "SOA") { print "ERROR ($ns): Expected SOA, got " . ($soa_req->answer)[0]->type . " ($domain)\n"; next; } print "$domain has serial number: " . ($soa_req->answer)[0]->serial . "\n\n" if $DEBUG; $serial = ($soa_req->answer)[0]->serial if $ns eq ($soa_req->answer)[0]->mname; $SOA{$ns} = ($soa_req->answer)[0]->serial; $i++; } if ($ns_req->header->ancount != $i) { print "$domain: An error has occurred\n"; next; } foreach my $record (keys %SOA) { print "$domain: SOA records doesn't match - $serial != $SOA{$record} ($record)\n" if $serial != $SOA{$record}; } } 0;