Hello Skeeve,
last time I checked parsing whois infos was a dread.. Infact the parsing for .com .org .info .name is different from the one needed for
it biz eu net and both .biz and .net can issue: "Maximum Daily connection limit reached. Lookup refused."
I ended using Net::Whois::Raw and Net::Whois::Parser but I needed mainly the status of the domain (well also nameservers and the whole mess..).
I used in web application using Dancer2, but I cannot publish here entirely: I hope you'll find the following stripped code useful
use Net::Whois::Raw;
use Net::Whois::Parser;
get '/aj2/whois/:search_for' => sub {
my $domain = route_parameters->get('search_for');
$domain =~ s/.*\.(.*)\.(.*)/$1\.$2/;
my @whois_ret = get_whois_infos($domain);
send_as JSON => { whois_raw => $whois_ret[1],
whois_status => $whois_ret[0]->{status},
whois_ns => (join ' ',@{$whois_ret[0]->{ns}}),
whois_help_text => &whois_help_text(split /\s/
+,$whois_ret[0]->{status})};
};
sub get_whois_infos {
my $dom = shift;
# strip eventual third level here?
my($raw_dominfo, $whois_server) = whois($dom);
my $parsed_info = parse_whois( raw => $raw_dominfo, domain => $who
+is_server );
# extract domain status data
my $pre_status = $parsed_info->{status} || $parsed_info->{domain_s
+tatus};
my $status;
if (ref $pre_status eq 'ARRAY'){
$status .= $_ for map{s/\s\S+/ /r} @{$pre_status};
}
else{$status = $pre_status ? $pre_status=~s/\s\S+/ /r : '-not defi
+ned-'}
# extract nameservers data
my @ns;
# the following should be ok for .com .org .info .name
if ($parsed_info->{nameservers} and ref $parsed_info->{nameservers
+} eq 'ARRAY'){
foreach my $ele(@{$parsed_info->{nameservers}}){
push @ns, $$ele{domain};
}
}
# the following is needed for it biz eu net
else{
my $switch = 0;
foreach my $line(split /\n/,$raw_dominfo){
# .it format
#Nameservers
#namserver1.isp.it
#namserver2.isp.it
# .eu format
#Name servers:
# namserver1.isp.it
# namserver2.isp.it
if ($dom =~ /\.it$|\.eu$/){
if ($line =~/name\s?servers/i){$switch = 1; next}
next unless $switch;
push @ns, $1 if $line =~/^\s*([\S]+)$/;
$switch = 0 if $line =~/^$/;
}
# .biz .net both can issue: "Maximum Daily connection lim
+it reached. Lookup refused."
#Name Server: namserver1.isp.it
#Name Server: namserver2.isp.it
elsif($dom =~/\.biz$|\.net$/){
push @ns, $1 if $line =~/^Name Server:\s+([\S]+)$/;
push @ns, "-$1-" if $line =~/(Maximum Daily connection
+ limit reached. Lookup refused)/;
}
else{
push @ns, "-Unable to parse whois data for $dom-";
+
}
}
}
return ({status=>$status, ns=>\@ns},"($whois_server answer)\n\n$ra
+w_dominfo");
}
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
|