digcomp.pl revision ec5347e2c775f027573ce5648b910361aa926c01
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews#!/usr/bin/perl
cfd262045c23cadb8415f0111f56995258f17361Evan Hunt#
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# Copyright (C) 2000, 2001 Internet Software Consortium.
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews#
cfd262045c23cadb8415f0111f56995258f17361Evan Hunt# Permission to use, copy, modify, and/or distribute this software for any
cfd262045c23cadb8415f0111f56995258f17361Evan Hunt# purpose with or without fee is hereby granted, provided that the above
cfd262045c23cadb8415f0111f56995258f17361Evan Hunt# copyright notice and this permission notice appear in all copies.
428dd5c588cfe0dc1519af728e6e75c10aeb4439Curtis Blackburn#
cfd262045c23cadb8415f0111f56995258f17361Evan Hunt# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
cfd262045c23cadb8415f0111f56995258f17361Evan Hunt# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
cfd262045c23cadb8415f0111f56995258f17361Evan Hunt# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
cfd262045c23cadb8415f0111f56995258f17361Evan Hunt# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
cfd262045c23cadb8415f0111f56995258f17361Evan Hunt# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
cfd262045c23cadb8415f0111f56995258f17361Evan Hunt# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
cfd262045c23cadb8415f0111f56995258f17361Evan Hunt# PERFORMANCE OF THIS SOFTWARE.
cfd262045c23cadb8415f0111f56995258f17361Evan Hunt
cfd262045c23cadb8415f0111f56995258f17361Evan Hunt# $Id: digcomp.pl,v 1.13 2007/06/18 23:47:27 tbox Exp $
cfd262045c23cadb8415f0111f56995258f17361Evan Hunt
cfd262045c23cadb8415f0111f56995258f17361Evan Hunt# Compare two files, each with the output from dig, for differences.
cfd262045c23cadb8415f0111f56995258f17361Evan Hunt# Ignore "unimportant" differences, like ordering of NS lines, TTL's,
cfd262045c23cadb8415f0111f56995258f17361Evan Hunt# etc...
cfd262045c23cadb8415f0111f56995258f17361Evan Hunt
$file1 = $ARGV[0];
$file2 = $ARGV[1];
$count = 0;
$firstname = "";
$status = 0;
$rcode1 = "none";
$rcode2 = "none";
open(FILE1, $file1) || die("open: $file1: $!\n");
while (<FILE1>) {
chomp;
if (/^;.+status:\s+(\S+).+$/) {
$rcode1 = $1;
}
next if (/^;/);
if (/^(\S+)\s+\S+\s+(\S+)\s+(\S+)\s+(.+)$/) {
$name = $1;
$class = $2;
$type = $3;
$value = $4;
if ($type eq "SOA") {
$firstname = $name if ($firstname eq "");
if ($name eq $firstname) {
$name = "$name$count";
$count++;
}
}
if ($entry{"$name ; $class.$type ; $value"} ne "") {
$line = $entry{"$name ; $class.$type ; $value"};
print("Duplicate entry in $file1:\n> $_\n< $line\n");
} else {
$entry{"$name ; $class.$type ; $value"} = $_;
}
}
}
close(FILE1);
$printed = 0;
open(FILE2, $file2) || die("open: $file2: $!\n");
while (<FILE2>) {
chomp;
if (/^;.+status:\s+(\S+).+$/) {
$rcode2 = $1;
}
next if (/^;/);
if (/^(\S+)\s+\S+\s+(\S+)\s+(\S+)\s+(.+)$/) {
$name = $1;
$class = $2;
$type = $3;
$value = $4;
if (($name eq $firstname) && ($type eq "SOA")) {
$count--;
$name = "$name$count";
}
if ($entry{"$name ; $class.$type ; $value"} ne "") {
$entry{"$name ; $class.$type ; $value"} = "";
} else {
print("Only in $file2 (missing from $file1):\n")
if ($printed == 0);
print("> $_\n");
$printed++;
$status = 1;
}
}
}
close(FILE2);
$printed = 0;
foreach $key (keys(%entry)) {
if ($entry{$key} ne "") {
print("Only in $file1 (missing from $file2):\n")
if ($printed == 0);
print("< $entry{$key}\n");
$status = 1;
$printed++;
}
}
if ($rcode1 ne $rcode2) {
print("< status: $rcode1\n");
print("> status: $rcode2\n");
$status = 1;
}
exit($status);