tester3
tester3

Reputation: 423

Bulk check domains avability with Perl

I need to check a list of domain names and get the list of domains with no NS (probably unregistered). I've already found a nice solution with ADNS and adnshost. The command "adnshost -a -tns domain.com" does what I need (The 4th column in the output will contain the result) but I want to achieve the same with Perl and Net::DNS::Async.

My code:

#!/usr/bin/perl -w

use strict;
use utf8;
use Net::DNS::Async;

my $c = new Net::DNS::Async(QueueSize => 1000, Retries => 3);

my $filename = 'domain_list.txt';

open(FH, '<', $filename);

while(<FH>){

chomp($url);

$c->add(\&callback, "$url");

}

$c->await();

sub callback {
my $response = shift;
print $response->string;
}

So, how do I get the needed info with Perl and Net::DNS::Async ?

Upvotes: 1

Views: 90

Answers (1)

user15398259
user15398259

Reputation:

You can add NS to the add arguments.

while (<FH>) {
    chomp;
    $c->add(\&callback, $_, 'NS');
}

$c->await();

sub callback {
    my $response = shift;
    unless ($response->answer) {
        my $host = join '.', @{$response->{question}[0]{qname}{label}};
        print "$host\n";
    }
}

$response->answer will be "empty" if there are no replies.

Upvotes: 1

Related Questions