I wrote a short script that allows you to reverse DNS lookup and traceroute each IP at the same time.

You will need a file named ip.txt in the same directory as this sourcecode, which has one IP address per line.

The traceroute results gets saved in ip-trace.txt. I used Socket and Net::Traceroute::PurePerl modules.

How to use

$ sudo perl ip-lookup-traceroute.pl >> ip-trace.txt

Source code in Perl

use Socket;
use Net::Traceroute::PurePerl;
$dbfile = "ip.txt";
print "Starting Trace!\n";
open (I, "$dbfile") or die "Unable to open: $dbfile";
my @lines = <i>;
close I;

$counter = 1;
foreach (@lines){
	print "Tracing $counter";

	$ip = $_;
	$ipinfo = gethostbyaddr(pack('C4',split('\.', $ip)), AF_INET);
	print gethostbyaddr(pack('C4',split('\.', $ip)), AF_INET);
	print "\n";

	 my $t = new Net::Traceroute::PurePerl(
         backend        => 'PurePerl', # this optional
         host           => $ip,
         debug          => 0,
         max_ttl        => 12,
         query_timeout  => 2,
         packetlen      => 40,
         protocol       => 'udp', # Or icmp
	if ($ipinfo eq ""){
	$ipinfo = "No address";

	open(OUT,">> ip-output.txt");
	print OUT "$ip	$ipinfo\n";




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s