-1
#!/usr/bin/perl

# S Validation Script

use strict;

use Net::DNS;
use Data::Dumper;

use Getopt::Long;

$| = 1;

my $USAGE = "$0 --file <domains file to read>";

my $input_filename = "";
GetOptions("--file=s" => \$input_filename) or die $USAGE;

if (! $input_filename || ! -e $input_filename){
    print "Missing or invalid --file option\n";
    die $USAGE;
}

open(my $fh, "<", $input_filename) or die "Can't open $input_filename for     reading: $!";
my @lines = <$fh>;
close($fh);

my $pass = 0;
my $fail = 0;

open(my $pass_fh, ">", $input_filename . ".pass") or die "Can't open     $input_filename.pass for writing: $!";
open(my $fail_fh, ">", $input_filename . ".fail") or die "Can't open     $input_filename.fail for writing: $!";

foreach my $hostname (@lines){
    $hostname =~ s/[\r\n]//;

     print "Working on $hostname: ";

     # servers to check
    my @servers = qw(8.8.8.8 208.76.121.64 8.8.4.4);

    my %results;
    foreach my $server (@servers) {
        $results{$server} = lookup( $hostname, $server );
    }

    my %inv = reverse %results; # invert results - it should have one key if all are the same
    if (scalar keys %inv > 1) { # if it has more than one key
        print "Fail\n";
        $fail++;
        print $fail_fh $hostname . "\n";
        #print "The results are different:\n";
        #print Data::Dumper->Dump( [ \%results ], ['results'] ), "\n";
    }
     else {
        print "Pass\n";
        $pass++;
        print $pass_fh $hostname . "\n";
    }
}

print "Total domains checked: " . ($pass + $fail) . "\n";
print "Pass: $pass\n";
print "Fail: $fail\n";
close($pass_fh);
close($fail_fh);

sub lookup {
    my ( $hostname, $server ) = @_;

    my $res = new Net::DNS::Resolver;
    $res->nameservers($server);
    my $packet = $res->query($hostname);

    if ( !$packet ) {
        warn "$server not returning any data for $hostname!\n";
        return;
    }
    my (@results);
    foreach my $rr ( $packet->answer ) {
        next unless $rr->type eq "A";
        push ( @results, $rr->address );
    }
    return join( ', ', sort @results );
}

When I run this script, I get the following errors:

    Attempt to reload Net/DNS/RR.pm aborted.
Compilation failed in require at /home/website/perl5/lib/perl5/x86_64-linux-thread-multi/Net/DNS/Packet.pm line 35.
BEGIN failed--compilation aborted at /home/website/perl5/lib/perl5/x86_64-linux-thread-multi/Net/DNS/Packet.pm line 35.
Compilation failed in require at /home/website/perl5/lib/perl5/x86_64-linux-thread-multi/Net/DNS/Resolver/Base.pm line 25.
BEGIN failed--compilation aborted at /home/website/perl5/lib/perl5/x86_64-linux-thread-multi/Net/DNS/Resolver/Base.pm line 25.
Compilation failed in require at /home/website/perl5/lib/perl5/x86_64-linux-thread-multi/Net/DNS/Resolver/UNIX.pm line 9.
BEGIN failed--compilation aborted at /home/website/perl5/lib/perl5/x86_64-linux-thread-multi/Net/DNS/Resolver/UNIX.pm line 9.
Compilation failed in require at /home/website/perl5/lib/perl5/x86_64-linux-thread-multi/Net/DNS/Resolver.pm line 27.
BEGIN failed--compilation aborted at /home/website/perl5/lib/perl5/x86_64-linux-thread-multi/Net/DNS/Resolver.pm line 30.
Compilation failed in require at /home/website/perl5/lib/perl5/x86_64-linux-thread-multi/Net/DNS.pm line 106.
BEGIN failed--compilation aborted at /home/website/perl5/lib/perl5/x86_64-linux-thread-multi/Net/DNS.pm line 106.
Compilation failed in require at ./script.pl line 7.
BEGIN failed--compilation aborted at ./script.pl line 7.

I made sure that all Net::DNS, Data::Dumper, and Getopt::Long modules are installed.

How do I fix this so that I can just type ./script --filename?

The filename is a list of domain names to validate.

technerdius
  • 253
  • 3
  • 6
  • 16
  • 1
    "Attempt to reload Net/DNS/RR.pm aborted." Are you sure this is the first error you get? What version of Net::DNS is installed? Have you tried downloading that version from cpan/backpan and running its tests? – user52889 Oct 06 '15 at 22:29
  • I just used Godaddy's perl module installer from cPanel. Their Cloud Linux does not offer permissions for me ot install anything using SSH or FTP. I had a feeling that it was them because I had this script tested on 3 other servers outside of Godaddy, one of them is Cloud Linux, and it works just fine. Godaddy is not taking any responsibility for it. So, it is getting aggravating. Luckily, they are not the only hosting company out there. If you answer the question, I can market yours as the answer. – technerdius Oct 07 '15 at 15:34

1 Answers1

0

I switched from using a Web hosting service to using a cloud computing solution. I now have a VM of CentOS 7 and Net::DNS and all of the perl modules I need work just fine.

The only snag I had was with Mail::CheckUser, but I realized I needed to install other dependencies, the Mail::CheckUser installed fine as well.

technerdius
  • 253
  • 3
  • 6
  • 16