digcomp.pl 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/usr/bin/perl
  2. #
  3. # Copyright (C) 2004, 2007 Internet Systems Consortium, Inc. ("ISC")
  4. # Copyright (C) 2000, 2001 Internet Software Consortium.
  5. #
  6. # Permission to use, copy, modify, and/or distribute this software for any
  7. # purpose with or without fee is hereby granted, provided that the above
  8. # copyright notice and this permission notice appear in all copies.
  9. #
  10. # THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  11. # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  12. # AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  13. # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  14. # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  15. # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. # PERFORMANCE OF THIS SOFTWARE.
  17. # Compare two files, each with the output from dig, for differences.
  18. # Ignore "unimportant" differences, like ordering of NS lines, TTL's,
  19. # etc...
  20. $file1 = $ARGV[0];
  21. $file2 = $ARGV[1];
  22. $count = 0;
  23. $firstname = "";
  24. $status = 0;
  25. $rcode1 = "none";
  26. $rcode2 = "none";
  27. open(FILE1, $file1) || die("open: $file1: $!\n");
  28. while (<FILE1>) {
  29. chomp;
  30. if (/^;.+status:\s+(\S+).+$/) {
  31. $rcode1 = $1;
  32. }
  33. next if (/^;/);
  34. if (/^(\S+)\s+\S+\s+(\S+)\s+(\S+)\s+(.+)$/) {
  35. $name = $1;
  36. $class = $2;
  37. $type = $3;
  38. $value = $4;
  39. if ($type eq "SOA") {
  40. $firstname = $name if ($firstname eq "");
  41. if ($name eq $firstname) {
  42. $name = "$name$count";
  43. $count++;
  44. }
  45. }
  46. if ($entry{"$name ; $class.$type ; $value"} ne "") {
  47. $line = $entry{"$name ; $class.$type ; $value"};
  48. print("Duplicate entry in $file1:\n> $_\n< $line\n");
  49. } else {
  50. $entry{"$name ; $class.$type ; $value"} = $_;
  51. }
  52. }
  53. }
  54. close(FILE1);
  55. $printed = 0;
  56. open(FILE2, $file2) || die("open: $file2: $!\n");
  57. while (<FILE2>) {
  58. chomp;
  59. if (/^;.+status:\s+(\S+).+$/) {
  60. $rcode2 = $1;
  61. }
  62. next if (/^;/);
  63. if (/^(\S+)\s+\S+\s+(\S+)\s+(\S+)\s+(.+)$/) {
  64. $name = $1;
  65. $class = $2;
  66. $type = $3;
  67. $value = $4;
  68. if (($name eq $firstname) && ($type eq "SOA")) {
  69. $count--;
  70. $name = "$name$count";
  71. }
  72. if ($entry{"$name ; $class.$type ; $value"} ne "") {
  73. $entry{"$name ; $class.$type ; $value"} = "";
  74. } else {
  75. print("Only in $file2 (missing from $file1):\n")
  76. if ($printed == 0);
  77. print("> $_\n");
  78. $printed++;
  79. $status = 1;
  80. }
  81. }
  82. }
  83. close(FILE2);
  84. $printed = 0;
  85. foreach $key (keys(%entry)) {
  86. if ($entry{$key} ne "") {
  87. print("Only in $file1 (missing from $file2):\n")
  88. if ($printed == 0);
  89. print("< $entry{$key}\n");
  90. $status = 1;
  91. $printed++;
  92. }
  93. }
  94. if ($rcode1 ne $rcode2) {
  95. print("< status: $rcode1\n");
  96. print("> status: $rcode2\n");
  97. $status = 1;
  98. }
  99. exit($status);