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 => $whois_server ); # extract domain status data my $pre_status = $parsed_info->{status} || $parsed_info->{domain_status}; 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 defined-'} # 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 limit 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$raw_dominfo"); }