Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2024-04-25 11:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found