Hi, this script queries the defined list of DNS servers and grabs the serial numbers for the listed zones. It then compares them against each other and logs if they match or not. It may not be pretty, but it works !

But, the bit I'm struggling with now is how best to do the serial number comparison if the number of DNS server in the list changes - that is if I add in more or remove DNS server IPs to the list, I don't have to manually go and add/remove the serial number references for the check - I want to make the serial compare "dynamic", based on the number of DNS servers.

I'm okay with just comparing all other serials to the first serial number, rather than comparing all possible combinations.

fyi - I'm writing all the results out to a file for reference, in addition to sending errors only to STDOUT. Thanks

#!/usr/bin/env perl use strict; use warnings; use Net::DNS; use 5.010; my @nameservers = qw(8.8.8.8 4.2.2.2); my @errors; open(my $resultsfh, '>', "results-serials.csv") or die "cannot open > results-serials.csv: $!"; print $resultsfh "Result,Zone"; foreach (@nameservers) { print $resultsfh ",Serial for: $_"; } print $resultsfh "\n"; while (<DATA>) { my $fqdn = $_; chomp $fqdn; my @serials; my $res = Net::DNS::Resolver->new; $res->tcp_timeout(2); $res->udp_timeout(2); foreach my $ns (@nameservers) { $res->nameservers($ns); my $reply = $res->query("$fqdn", "SOA"); if ($reply) { push(@serials, ($reply->answer)[0]->serial); } else { push(@serials, $res->errorstring); } } # Compare Serials no warnings 'numeric'; if ($serials[0] == $serials[1]) { say $resultsfh "MATCH,$fqdn,$serials[0],$serials[1]"; } else { say $resultsfh "MISMATCH,$fqdn,$serials[0],$serials[1]"; push @errors, "MISMATCH.$fqdn,$serials[0],$serials[1]"; } } if (@errors) { say "ERRORS:"; foreach (@errors) { say "$_"; } } __DATA__ google.com apple.com

In reply to Compare variables when the number of them vary by stroke

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.