automated IP WHOIS lookup

If you have a program or script that you'd like to give away or sell, this is the place to do it. All offers should include contact info.

Moderators: BBear, theunknownhost, flaguy

Post Reply
Hard Drive Crasher
Posts: 767
Joined: Sun Nov 21, 2004 2:19 pm
Location: Lexington, KY

automated IP WHOIS lookup

Post by m2 » Wed Aug 27, 2008 3:05 pm

I needed WHOIS for a number if IPs to find out their country. CPAN has a great package called Net::Whois::IANA that automates the WHOIS lookup. Here's the PERL code to loop through a text file (file name is iplist.txt, 1 IP on each line) and print results. I only needed the country and regional WHOIS. There's other WHOIS data available in comments if you need that data. (The sleep command limits traffic to the regional servers so the script isn't blocked. You might have to increase the sleep time or run batches if you analyze a lot of IPs.)

Code: Select all

#!/usr/bin/perl -w
use strict;
use Net::Whois::IANA;
print "\n";
open IP, '<iplist.txt' || die "Can't open iplist.txt";
while (<IP>) {
  my $ip = $_;
  my $iana = new Net::Whois::IANA;
  print $ip, ": Country: ", $iana->country(), ' (', $iana->server(), ")\n";
#  print "Netname: " . $iana->netname() . "\n";
#  print "Descr: "   . $iana->descr()   . "\n";
#  print "Status: "  . $iana->status()  . "\n";
#  print "Source: "  . $iana->source()  . "\n";
#  print "Server: "  . $iana->server()  . "\n";
#  print "Inetnum: " . $iana->inetnum() . "\n";
#  print "CIDR: "    . $iana->cidr()    . "\n";
  sleep 1;


Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest