DNS checks while migrating
Spotted a nice article on Perl Maven and decided to share another way of doing DNS resolving, which might be a bit more convenient and should account for multiple IPs returned. Use it with watch and you're all set. NB: Change nameservers to the ones you like and maybe use Getopt::Long or something similar to get them and the hostname :)
use strict;
use warnings;
use 5.010;
use Net::DNS::Dig;
use NetAddr::IP::Util qw(inet_ntoa);
my $hostname = $ARGV[0]||"google.com";
my @nameservers = qw<8.8.8.8 207.200.7.21 91.207.40.2>;
foreach my $name_server (@nameservers) {
my @netaddrs = Net::DNS::Dig->new( PeerAddr => $name_server )->for( $hostname )->rdata();
printf "%-20s", $name_server;
say @netaddrs ? join ", ", map { inet_ntoa($_) } @netaddrs : "FAILED";
}
© Do-Know.com