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

Hello. I'm trying to make a perl script that gets the ip range from a certain AS. I'm using the Net::Whois::RIPE package for it. I'm a beginner in perl and i'm stuck soon. The output that I get from my code is.
Net::Whois::RIPE::Object=HASH(0x315a608)Net::Whois::RIPE::Object=HASH( +0x315c9f0) Net::Whois::RIPE::Object=HASH(0x315ccb4)Net::Whois::RIPE::Object=HASH( +0x315d068) Net::Whois::RIPE::Object=HASH(0x315d32c)Net::Whois::RIPE::Object=HASH( +0x315d6e0) Net::Whois::RIPE::Object=HASH(0x315d938)Net::Whois::RIPE::Object=HASH( +0x315dc50) ...
Here's my code:
use Net::Whois::RIPE; use strict; use warnings; my $server = "whois.ripe.net"; my $as = "LEASEWEB"; my $whois = Net::Whois::RIPE->new($server); my @output = $whois->query($as); foreach my $line (@output) { print $line; } exit;
Once I get the output I think i'll be able to filter out the ip ranges. Thx in advance

Replies are listed 'Best First'.
Re: Ripe Whois lookup
by dwm042 (Priest) on Aug 13, 2008 at 20:22 UTC
    I can't test this (because WHOIS queries are blocked from my current location), but if I'm reading the docs correctly, the query command returns Net::Whois::RIPE::Object objects, as opposed to something printable. But you should be able to get some kind of more meaningful response by changing

    print $line;
    to something like

    foreach $attribute ($line->attributes()) { foreach $value ($line->$attribute()) { printf "%s: %-s\n", $attribute, $value; } }
    For more details, my example was cribbed from this page.
Re: Ripe Whois lookup
by geoffleach (Scribe) on Aug 13, 2008 at 20:19 UTC
    Have a look at Net::Whois::RIPE::Object. You need something like $query->nic_hdl (from the POD). I suspect that if your run your script in the debugger and enter 'x $line' you'll see what you need.
Re: Ripe Whois lookup
by marto9 (Beadle) on Aug 13, 2008 at 21:11 UTC
    Thx for the help. I ajusted the script a little and now I atleast have some output.
    use Net::Whois::RIPE; $server = "whois.ripe.net"; $as = "LEASEWEB"; $whois = Net::Whois::RIPE->new($server); $query = $whois->query($as); $output = $query->content; @lijn = split(/\n/,$output); foreach $line (@lijn) { @lines = split(/:/, $line); next unless ($lines[0] =~ /inetnum/); $lines[1] =~ s/^\s+|\s+$//g; print $lines[1]."\n"; } exit;
    It all works fine now. But there's just one more problem. I don't get all the ranges from that AS. When I type in the AS in www.ripe.net, I get way more. I'll look further. edit1:I adjusted the code a little bit more. edit2:I'll try to explain the problem that I have now with examples. This is the output from my script:
    % This is the RIPE Whois query server #1. % The objects are in RPSL format. % % Rights restricted by copyright. % See http://www.ripe.net/db/copyright.html % Note: This output has been filtered. % To receive output for a database update, use the "-B" flag. % Information related to '62.212.64.0 - 62.212.64.255' inetnum: 62.212.64.0 - 62.212.64.255 netname: LEASEWEB descr: LeaseWeb descr: P.O. Box 93054 descr: 1090BB AMSTERDAM descr: Netherlands descr: www.leaseweb.com remarks: Please send email to "abuse@leaseweb.com" for complain +ts remarks: regarding portscans, DoS attacks and spam. country: NL admin-c: LSW1-RIPE tech-c: LSW1-RIPE status: ASSIGNED PA mnt-by: OCOM-MNT source: RIPE # Filtered
    And this is what I get when I enter thesame AS in www.ripe.net:
    % This is the RIPE Whois query server #1. % The objects are in RPSL format. % % Rights restricted by copyright. % See http://www.ripe.net/db/copyright.html % Note: This output has been filtered. % To receive output for a database update, use the "-B" flag. % Information related to '62.212.64.0 - 62.212.64.255' inetnum: 62.212.64.0 - 62.212.64.255 netname: LEASEWEB descr: LeaseWeb descr: P.O. Box 93054 descr: 1090BB AMSTERDAM descr: Netherlands descr: www.leaseweb.com remarks: Please send email to "abuse@leaseweb.com" for complai +nts remarks: regarding portscans, DoS attacks and spam. country: NL admin-c: LSW1-RIPE tech-c: LSW1-RIPE status: ASSIGNED PA "status:" definitions mnt-by: OCOM-MNT source: RIPE # Filtered person: RIP Mean address: P.O. Box 93054 address: 1090BB AMSTERDAM address: Netherlands phone: +31 20 3162880 fax-no: +31 20 3162890 abuse-mailbox: abuse@leaseweb.com nic-hdl: LSW1-RIPE mnt-by: OCOM-MNT source: RIPE # Filtered % Information related to '62.212.78.0 - 62.212.78.255' inetnum: 62.212.78.0 - 62.212.78.255 netname: LEASEWEB descr: LeaseWeb descr: P.O. Box 93054 descr: 1090BB AMSTERDAM descr: Netherlands descr: www.leaseweb.com remarks: Please send email to "abuse@leaseweb.com" for complai +nts remarks: regarding portscans, DoS attacks and spam. country: NL admin-c: LSW1-RIPE tech-c: LSW1-RIPE status: ASSIGNED PA "status:" definitions mnt-by: OCOM-MNT source: RIPE # Filtered person: RIP Mean address: P.O. Box 93054 address: 1090BB AMSTERDAM address: Netherlands phone: +31 20 3162880 fax-no: +31 20 3162890 abuse-mailbox: abuse@leaseweb.com nic-hdl: LSW1-RIPE mnt-by: OCOM-MNT source: RIPE # Filtered % Information related to '62.212.68.0 - 62.212.68.255' inetnum: 62.212.68.0 - 62.212.68.255 netname: LEASEWEB descr: LeaseWeb descr: P.O. Box 93054 descr: 1090BB AMSTERDAM descr: Netherlands descr: www.leaseweb.com remarks: Please send email to "abuse@leaseweb.com" for complai +nts remarks: regarding portscans, DoS attacks and spam. country: NL admin-c: LSW1-RIPE tech-c: LSW1-RIPE status: ASSIGNED PA "status:" definitions mnt-by: OCOM-MNT source: RIPE # Filtered person: RIP Mean address: P.O. Box 93054 address: 1090BB AMSTERDAM address: Netherlands phone: +31 20 3162880 fax-no: +31 20 3162890 abuse-mailbox: abuse@leaseweb.com nic-hdl: LSW1-RIPE mnt-by: OCOM-MNT source: RIPE # Filtered ...
    So with my script I only get the first object. I need my script to get more objects, like on www.ripe.net
      I am used foreach $inet ($whois->query($as)) { print $inet->address, "\n"; } instead of simple $query = $whois->query($as); $output = $query->content; to output address lines. This way you probably can get full output.