#!/usr/bin/perl # Needed packages use strict "vars"; use Getopt::Std; use Term::ANSIColor; use DBI; # command line options my $opt_string = "hf:"; getopts( "$opt_string", \my %opt ) or usage() and exit(1); if (not $opt{'f'}) { print "Please provide a filename! \n"; usage(); exit 0; } if ( $opt{'h'} ) { usage(); exit 0; } ##################################################### # Main part my $FILE= $opt{'f'}; open(LOG, "$FILE") or die "Error opening $FILE $!\n"; while ( my $line = ) { # print color 'green'; print $line; # print color 'reset'; findIP($line); } close(LOG); exit 0; ##################################################### # subroutines sub usage { print "Usage:\n"; print "-h for help\n"; print "-f File containing the site addresses from Alexa to process \n"; } sub findIP { my $IP; my $counter=0; my $entry; my $SERVER_IP1 = 0; my $SERVER_IP2 = 0; my $SERVER_IP3 = 0; my $SERVER_IP4 = 0; my $SERVER_IP5 = 0; open(NSLOOKUP, "nslookup $_[0] | ") or die "Error doing NSLOOKUP $!\n"; while (my $targetline = and $counter < 6) { if ($targetline =~/Address: (.*)(.*)(.*)(.*)$/) { $counter+=1; if ($counter == 1){ $SERVER_IP1 = "$1$2$3$4" } if ($counter == 2){ $SERVER_IP2 = "$1$2$3$4" } if ($counter == 3){ $SERVER_IP3 = "$1$2$3$4" } if ($counter == 4){ $SERVER_IP4 = "$1$2$3$4" } if ($counter == 5){ $SERVER_IP5 = "$1$2$3$4" } } } if ( $counter == 0){ $entry = "www." . $_[0]; } else { $entry = $_[0]; } open(NSLOOKUP, "nslookup $entry | ") or die "Error doing NSLOOKUP $!\n"; while (my $targetline = ) { if ($targetline =~/Address: (.*)(.*)(.*)(.*)$/) { if ($counter ==0) { $IP= "$1$2$3$4"; $SERVER_IP1 = "$1$2$3$4"; findlocation2($IP); } else { $IP= "$1$2$3$4"; print "$IP,"; findlocation($IP); } } } print "IP1:" . $SERVER_IP1 . ", IP2:" . $SERVER_IP2 . ", IP3:" . $SERVER_IP3 . ", IP4:" . $SERVER_IP4 . ", IP5:" . $SERVER_IP5 . "\n"; print "\n"; # print "----------------------------------------------------------------------\n"; } sub findlocation { open(GEO,"wget -q -O - http://www.geoiptool.com/en/?IP=$_[0] | ") or die "Error creating file $!\n"; while ( my $targetline = ) { if ($targetline =~ /^.*Country<\/strong>: (.*)
/) { # print "IP GEO-LOCATION is: "; # print color 'bold red'; print $1; # print color 'reset'; print "\n"; } } return 0 ; } sub findlocation2 { my $country_code; open (GEO, "whois -h whois.cymru.com ' -v $_[0] ' | ") or die "Error creating file $!\n"; while ( my $targetline = ) { # print $targetline; if ($targetline =~ /^\d+\s+\|\s+\d+.\d+.\d+.\d+\s+\|\s+\d+.\d+.\d+.\d+\/\d+\s+\|\s+([A-Z]*)/) { $country_code = $1; # print $country_code; open(COUNTRYCODES,"wget -q -O - http://www.iso.org/iso/country_names_and_code_elements_txt | ") or die "Error creating file $!\n"; while ( my $targetline2 = ) { if ($targetline2 =~/(.*)\;$country_code/) { print " " . $country_code . "=>" . $1 . " "; } } } } }