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.

In reply to Re: whois modules? Any recommendation? by Discipulus
in thread whois modules? Any recommendation? by Skeeve

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.