Perl script for batch whois

Posted: February 14, 2013 in Perl, snippets

I created a perl script that reads a file with domains to check and output the valid ones.It can also go through domain name combinations.

#!/usr/bin/perl

sub whois
{
#print “doing whois for “.$_[0].”: “;
my $domain = $_[0];
$domain =~ s/www\.//g;
open(WHOIS_CMD, “whois -h whois.isoc.org.il \”$domain\”|”) or die “Can’t run ‘$whois_cmd $domain’\n$!\n”;
$i=0;
while(<WHOIS_CMD>)
{ # each line of output is put into $_
if ($_ =~ /No data was found to match the request criteria|No match|A C C E S S D E N I E D/i)
{
#print $_;
return 0;
}
}
return 1;
}
if ($#ARGV>(-1))
{
print $ARGV[0];

my $file = $ARGV[0];
open my $domains, $file or die “Could not open $file: $!”;

while( my $domain = <$domains>)
{
chomp($domain);
if (whois($domain)==1)
{
print “$domain : ok\n”;
}
else
{
print “$domain : fail\n”;
}
}

close $domains;
}

print “\n\n”;

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s