Created
December 3, 2022 21:00
-
-
Save ilyaevseev/8168ead94a41c8e42a568f0936c7b83a to your computer and use it in GitHub Desktop.
Validate domain NS records against whois and NS servers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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