• Welcome to Hurricane Electric's IPv6 Tunnel Broker Forums.

Perl script for daily digs, traceroutes, pings, etc

Started by tsemczyszyn, June 21, 2010, 12:54:20 PM

Previous topic - Next topic

tsemczyszyn

I wrote myself a little Perl script that will take an IPv6-enabled domain as an argument and do each of the daily tests for extra points. It pauses so you can paste the output into the website. I find it quite handy so I thought I'd toss it up here if anyone would like to use it.


#!/usr/bin/perl
use IO::Handle;

if (@ARGV != 1) {
  print "You must supply only one argument: the IPv6 domain you wish to use.\n\n";
  exit(1);
}



$domain = $ARGV[0];
@ip_list = `dig AAAA $domain +short`;

foreach (@ip_list) {
  if ($_ =~ /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/ )
  {
     $ip = $_;
     last;
  }
}

if (!$ip_list[0]) {
  print "Not an IPv6-enabled domain\n";
  exit(1);
}

system("clear");
print "Executing traceroute6 to $domain...\n\n\n";

system("traceroute6 $domain");

print "\n\nPress enter to continue...\n\n";
$key = <STDIN>;

system("clear");
print "Executing forward lookup on $domain...\n\n\n";

system("dig AAAA $domain");

print "Press enter to continue...\n\n";
$key = <STDIN>;

system("clear");
print "Executing reverse lookup on $domain's IP...\n\n\n";

system("dig -x $ip");


print "Press enter to continue...\n\n";
$key = <STDIN>;

system("clear");
print "Executing ping6 on $domain...\n\n\n";

system("ping6 -n -c 5 $domain");

print "\n\nPress enter to continue...\n\n";
$key = <STDIN>;

system("clear");
print "Executing whois on $domain's IP...\n\n\n";

system("whois $ip");

print "\n\nPress enter to continue...\n\n";
$key = <STDIN>;

print "That's all for today!\n\n\n";


bgvaughan

Thanks!

Out of curiosity, why Perl instead of a BASH shell script or the like?

jimb

Perlre probably.  Parsing IPv6 addresses can be hairy.  I'd rather do it in Perl also.  :P