-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 );
}

このスクリプトを実行すると、次のエラーが発生します。

    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 と入力できるようにするにはどうすればよいですか?

ファイル名は、検証するドメイン名のリストです。

4

1 に答える 1

0

Web ホスティング サービスの使用からクラウド コンピューティング ソリューションの使用に切り替えました。現在、CentOS 7 と Net::DNS の VM があり、必要なすべての perl モジュールが正常に動作しています。

私が持っていた唯一の問題は Mail::CheckUser でしたが、他の依存関係をインストールする必要があることに気付きました。Mail::CheckUser も正常にインストールされました。

于 2015-10-14T05:26:48.173 に答える