package Net::Whois::RIS;

use warnings;
use strict;
use IO::Socket;

require Exporter;
use AutoLoader qw(AUTOLOAD);

our @ISA = qw(Exporter);

our %EXPORT_TAGS = (
    'all' => [


our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT    = qw( );

sub new {

    my ($this) = @_;
    my $class = ref($this) || $this;
    my $self = {};
    bless $self, $class;
    $self->{host} = "";
    $self->{url} =
    return $self;


sub getIPInfo {

    my ( $self, $ip ) = @_;
    my $con = IO::Socket::INET->new( PeerAddr => $self->{host}, PeerPort => 43 )
      or die();
    print $con $ip . "\n";
    my $x;
    while (<$con>) {
        $x = $x . $_;
    my %h = ();
    foreach ( split( /\n/, $x ) ) {
        next if (m/^%/);
        next if (m/^$/);
        my @d = split( /:/, $_ );
        $d[1] =~ s/^\s+//;
        $h{ $d[0] } = $d[1];
    $self->{get} = \%h;
    return $self;

sub getASNInfo {

    my ( $self, $asn ) = @_;
    use Scrappy;

    my $spidy = Scrappy->new;
    my $url   = $self->{url};
    $self->{prefixes} = "";
    $url =~ s/\|ASN\|/$asn/;

            'table td a' => sub {
                my $data = shift->text;
                if ( defined($data) ) {
                    if ( !( $data =~ m/W/ ) ) {
                        $self->{prefixes} = $self->{prefixes} . $data . "\n";
                else { $self->{prefixes} = undef; }

    return $self;

sub getPrefixes {
    my ($self) = @_;

    return $self->{prefixes};

sub getOrigin {
    my ($self) = @_;

    return $self->{get}{'origin'};

sub getDescr {
    my ($self) = @_;

    return $self->{get}{'descr'};

sub getRoute {
    my ($self) = @_;

    return $self->{get}{'route'};
1;    # End of Net::Whois::RIS

=head1 NAME

Net::Whois::RIS - Whois lookup on RIPE RIS

=head1 VERSION

Version 0.6

our $VERSION = '0.6';


The module query the RIPE Routing Information Service (RIS) whois to get
information about a specific IP address. You can get information
like the AS number announcing the IP address/network.

    use Net::Whois::RIS;

    my $foo = Net::Whois::RIS->new();
    print $foo->getOrigin();
    print $foo->getDescr();

The module can also query the Web interface to gather additional
information via the Ajax interface of the RIPE RIS dashboard. The
main use is to gather the list of announced prefixes for an ASN.

    use Net::Whois::RIS;

    my $foo = Net::Whois::RIS->new();
    print $foo->getPrefixes();

The module's first objective was to provide an easy IP to ASN
mapping interface via Perl.

For more information about the RIPE Routing Information Service :

=head1 methods

The object  oriented interface to C<Net::Whois::RIS> is  described in this

The following methods are provided:

=over 4

=item Net::Whois::RIS->new();

This constructor returns a new C<Net::Whois::RIS> object encapsulating whois
request to RIPE RIS.

=item getIPInfo($ipaddress);

The method is gathering the information from the RIS service using the whois protocol.

=item getASNInfo($asn);

The method is gathering the prefixes announced via the RIS service Ajax (as the
whois RIS interface is not providing the service).

=item getPrefixes();

The method returns the list of prefixes announced by an ASN.

=item getOrigin();

The method returns a string containing the originating ASN of the network/IP requested.

=item getDescr();

The method returns a string containing the description of the ASN announcing the network/IP requested.

=item getRoute();

The method returns a string containing the most specific route match for the requested network/IP address.


=head1 AUTHOR

Alexandre Dulaunoy, C<< <adulau at> >>

=head1 BUGS

Please report any bugs or feature requests to C<bug-net-whois-ris at>, or through
the web interface at L<>.  I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Net::Whois::RIS

You can also look for information at:

=over 4

=item * RT: CPAN's request tracker


=item * AnnoCPAN: Annotated CPAN documentation


=item * CPAN Ratings


=item * Search CPAN





Copyright 2010 Alexandre Dulaunoy.

This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.

See for more information.