CSF: IP tracking of DNS name – perl tool

Simple code on perl for tracking of list of IP of DNS name:

#!/bin/env perl

use strict;
use Socket;
my $hostname = 'bitbucket.org';
my %ips;

while(1){
  my @addresses = gethostbyname($hostname) or die "Can't resolve $hostname: $!\n";
  @addresses = map { inet_ntoa($_) } @addresses[4 .. $#addresses];
  #print join(", ", @addresses);
  foreach my $item (@addresses){
     $ips{$item} = $ips{$item}+1;
  }
  print "\033[2J";    #clear the screen
  print "\033[0;0H"; #jump to 0,0
  print "\t$hostname\n"; 
  while( my( $key, $val ) = each %ips) {
        print "\t$key\t=>$val\n";
  }     
  sleep 30;
}
Scroll to top