【问题标题】:Perl DNS Validation using modules Net::DNS, Data::Dumper and Getopt::Long errorsPerl DNS 验证使用模块 Net::DNS、Data::Dumper 和 Getopt::Long 错误
【发布时间】:2015-10-06 17:25:04
【问题描述】:
#!/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?

文件名是要验证的域名列表。

【问题讨论】:

  • "尝试重新加载 Net/DNS/RR.pm 已中止。"你确定这是你得到的第一个错误吗?安装了哪个版本的 Net::DNS?您是否尝试过从 cpan/backpan 下载该版本并运行它的测试?
  • 我刚刚使用了来自 cPanel 的 Godaddy 的 perl 模块安装程序。他们的 Cloud Linux 不为我提供使用 SSH 或 FTP 安装任何东西的权限。我有一种感觉是他们,因为我在 Godaddy 之外的其他 3 台服务器上测试了这个脚本,其中之一是 Cloud Linux,它工作得很好。 Godaddy 对此不承担任何责任。所以,情况越来越严重。幸运的是,他们并不是唯一的托管公司。如果你回答了这个问题,我可以推销你的作为答案。

标签: perl validation dns getopt-long data-dumper


【解决方案1】:

我从使用 Web 托管服务切换到使用云计算解决方案。我现在有一个 CentOS 7 和 Net::DNS 的虚拟机,我需要的所有 perl 模块都可以正常工作。

我遇到的唯一障碍是 Mail::CheckUser,但我意识到我需要安装其他依赖项,Mail::CheckUser 也安装得很好。

【讨论】:

    猜你喜欢
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多