Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

whois modules? Any recommendation?

by Skeeve (Parson)
on Jul 03, 2019 at 14:28 UTC ( [id://11102359]=perlquestion: print w/replies, xml ) Need Help??

Skeeve has asked for the wisdom of the Perl Monks concerning the following question:

I need to query whois data for domains and IP addresses.
I'm wondering which modules you recommend.
I've tried:
    Net::Whois
    It does not even install due to a bug reported in 2010
    Net::Whois::IP
    I currently use this for IP lookup
    Net::XWhois
    Allows access to fields via AUTOLOAD. But how would you access "org-name" via AUOLOAD? And why does it not give "organisation"?
    Net::Whois::ARIN
    Net::Whois::IANA
    Both are just for IPs, but IPs I already can query with Net::Whois::IP

s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Replies are listed 'Best First'.
Re: whois modules? Any recommendation?
by Discipulus (Canon) on Jul 04, 2019 at 08:30 UTC
    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.
Re: whois modules? Any recommendation?
by tobyink (Canon) on Jul 06, 2019 at 09:52 UTC

    I haven't tried any of these modules, but to answer your question about calling methods with a hyphen in the name:

    my $whois = Net::XWhois->new(...); my $orgname = $whois->${\ "org-name" };

    Or:

    my $whois = Net::XWhois->new(...); my $orgname = do { my $m = "org-name"; $whois->$m };
Re: whois modules? Any recommendation?
by daxim (Curate) on Jul 03, 2019 at 15:05 UTC
    The command-line tool shipped by major distros is pretty good.
    › rpm -q --qf %{URL} whois http://www.linux.it/~md/software/
      Maybe.
      But I'd like not to have to fork new processes for the lookup.

      s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
      +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11102359]
Approved by hippo
Front-paged by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-03-29 23:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found