0

I'm trying to write a Perl script that displays whois information for various servers. The whois servers, however return all types of disclaimers and other text within the replies. Net::Whois::Raw does have options to strip these disclaimers, but I can't get it to work.

Here's how I tried it:

#!/usr/bin/perl
use strict;
use warnings;

my $OMIT_MSG = 2;
my $CHECK_FAIL = 2;
my $USE_CNAMES = 1;

use Net::Whois::Raw qw(whois $OMIT_MSG $CHECK_FAIL $USE_CNAMES);

die "Incorrect arguments\n" unless (@ARGV);

for (my $i = 0; $i < @ARGV; $i++)
{
    print "\nWhois info : " . $ARGV[$i] . "\n\n\n";

    eval
    {
        my $whoisinfo = whois($ARGV[$i]);
        print $whoisinfo;
    };
    if ($@)
    {
        print "Error while retrieving whois details.";
    }
    print "\n";
}

I'm sorry if this is probably a dumb question, but can anyone point out what I'm doing wrong here?

Thanks in advance.

  • What does "not work" mean? – ikegami May 06 '13 at 07:42
  • Where did you get `use Net::Whois::Raw qw(whois $OMIT_MSG $CHECK_FAIL $USE_CNAMES);`?! There's nothing remotely similar to that in the [docs](http://search.cpan.org/perldoc?Net::Whois::Raw). – ikegami May 06 '13 at 07:44
  • By "not work" I mean disclaimers aren't stripped. And $OMIT_MSG is here: http://search.cpan.org/~corris/Net-Whois-Raw-0.23/lib/Net/Whois/Raw.pm –  May 06 '13 at 07:55
  • I've got to admit I've not seen that perl module fail before, and if you need to add anything to your script then in your outer for loop you might want to put some regular expressions to filter unwanted lines, that said I'm a big believer in stringing unix tools together (as is the design) 'see my answer below' , if it where me I'd be tempted to feed the output of 'whois' into grep, then into your perlscript for display. – shawty May 29 '13 at 18:27
  • As a side note, have a look at Net::DRI (I am its developer), it takes a different approach but one part of it gives you access to whois data as Perl objects. It would of course need to be updated for a bunch of new gTLDs. – Patrick Mevzek Jan 03 '18 at 20:23

3 Answers3

1

May not be exactly what your looking for, but I'm currently doing some work parsing the RAW whois database files (Which you can download in their complete form, from ftp://ftp.ripe.net/ in the 'ripe/database' directory)

Like you I wanted to filter out the disclaimers, but I have different needs, mostly the fact that I'm preprocessing the files before feeding them to a database script to be inserted into a database.

Anyway, I'm using the following command line to pre filter the plain text database files:

cat ripe.db.as-block | grep -v '^\s*#' | grep -v '^remarks:\s*\*'

I guess following from that, you could pipe the output into your perl script, or write it to a new file using the > operator, then process that new file with your perl script.

This will also work on windows using the GnuWin32 toolset from sourceforge, which gives you windows compatible command line binaries that mirror their linux counter parts, but you will need to tweak the quotes, mostly from ' to "

as an example of what it strips:

this....

#
# The contents of this file are subject to
# RIPE Database Terms and Conditions
#
# http://www.ripe.net/db/support/db-terms-conditions.pdf
#

as-block:       AS1877 - AS1901
descr:          RIPE NCC ASN block
remarks:        These AS Numbers are further assigned to network
remarks:        operators in the RIPE NCC service region. AS
remarks:        assignment policy is documented in:
remarks:        <http://www.ripe.net/ripe/docs/asn-assignment.html>
remarks:        RIPE NCC members can request AS Numbers using the
remarks:        form available in the LIR Portal or at:
remarks:        <http://www.ripe.net/ripe/docs/asnrequestform.html>
org:            ORG-NCC1-RIPE
admin-c:        DUMY-RIPE
tech-c:         DUMY-RIPE
mnt-by:         RIPE-DBM-MNT
mnt-lower:      RIPE-NCC-HM-MNT
changed:        unread@ripe.net 20000101
source:         RIPE
remarks:        ****************************
remarks:        * THIS OBJECT IS MODIFIED
remarks:        * Please note that all data that is generally regarded as personal
remarks:        * data has been removed from this object.
remarks:        * To view the original object, please query the RIPE Database at:
remarks:        * http://www.ripe.net/whois
remarks:        ****************************

Ends up as this:

as-block:       AS1877 - AS1901
descr:          RIPE NCC ASN block
remarks:        These AS Numbers are further assigned to network
remarks:        operators in the RIPE NCC service region. AS
remarks:        assignment policy is documented in:
remarks:        <http://www.ripe.net/ripe/docs/asn-assignment.html>
remarks:        RIPE NCC members can request AS Numbers using the
remarks:        form available in the LIR Portal or at:
remarks:        <http://www.ripe.net/ripe/docs/asnrequestform.html>
org:            ORG-NCC1-RIPE
admin-c:        DUMY-RIPE
tech-c:         DUMY-RIPE
mnt-by:         RIPE-DBM-MNT
mnt-lower:      RIPE-NCC-HM-MNT
changed:        unread@ripe.net 20000101
source:         RIPE

The trick to the filtering is using a reverse grep that's the '-v' in the command line, what it essentially says is let every line pass EXCEPT for those that match the pattern, as opposed to it's normal invocation, where it's used to select wanted lines.

If you have extra criteria you want to filter out before processing, then all you need to do is just pipe more inverted grep commands onto the end using the pipe character.

shawty
  • 5,729
  • 2
  • 37
  • 71
1

I may be completely wrong, because I don't use Perl very often, and don't really understand the mechanics of use, but since $OMIT_MSGS is being exported from the module, I would have thought you don't want to pre-declare it with my, you want to assign to it after the module is loaded (but before you make any function calls):

use Net::Whois::Raw qw(whois $OMIT_MSG $CHECK_FAIL $USE_CNAMES);

$OMIT_MSG = 2;
$CHECK_FAIL = 2;
$USE_CNAMES = 1;
IMSoP
  • 89,526
  • 13
  • 117
  • 169
0
use Net::Whois::Raw;
$Net::Whois::Raw::OMIT_MSG = 1;
my $domain_info = whois('perl.com');

This works. It strips for Perl.com and Funet.fi - domains used as examples in documentation. But, as documentation says, it will not work for all domains.

flamey
  • 2,311
  • 4
  • 33
  • 40