#!/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 );
}
当我运行此脚本时,我收到以下错误:
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.
我确保安装了所有 Net::DNS、Data::Dumper 和 Getopt::Long 模块。
我该如何解决这个问题,以便我可以输入 ./script --filename?
文件名是要验证的域名列表。