Skip to content

Instantly share code, notes, and snippets.

@ilyaevseev
Created December 3, 2022 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilyaevseev/8168ead94a41c8e42a568f0936c7b83a to your computer and use it in GitHub Desktop.
Save ilyaevseev/8168ead94a41c8e42a568f0936c7b83a to your computer and use it in GitHub Desktop.
Validate domain NS records against whois and NS servers.
#!/usr/bin/perl
use strict;
use warnings;
use Storable qw/freeze/;
$Storable::canonical = 1; # https://www.perlmonks.org/?node_id=127254
die "Usage: $0 domain-name\n" unless @ARGV == 1;
my $domain = shift @ARGV;
open F, "whois $domain |" or die "Cannot run whois: $!\n";
my @nservers = sort map { s/[\.\r\n]+$//; my @a = split; lc $a[$#a] } grep { /nserver:/i or /name server:/i } <F>;
print $_,"\n" foreach "=== WHOIS ===",@nservers;
foreach my $s (@nservers) {
open F, "host -t ns $domain $s |" or die "Cannot query $s: $!\n";
my @ns = sort map { s/[\.\r\n]+$//; my @a = split; lc $a[$#a] } grep { /name server/ } <F>;
next if freeze(\@ns) eq freeze(\@nservers);
print $_,"\n" foreach "=== $s ===",@ns;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment