#!/usr/bin/env perl
# ====================[ tracepath-subnets                  ]====================
use constant {
  true=>  '1',
	false=> '',

  success=> 0,
	failure=> 1,
};

my $subnets = qw(10.0.0 10.0.1 10.1.0 10.1.1 192.168.1);
#y $subnets = qw(10.0.0 192.168.1);
#y $subnets = qw(10.0.0);
my @ip_successes = ();

foreach my $subnet ($subnets) {
	foreach my $host (1..254) {
		my $ip = $subnet.'.'.$host;

		print "tracepath-subnets: tracing path to localhost ${ip}... "; 
		if (qx{tracepath $ip} =~ m~no reply|send failed~) {
			print "(failure)\n";
		}
		else {
			print "(success)\n";
			push @ip_successes, $ip;
		}
	}

	print "tracepath-subnets: traced paths to localhosts\n(";

	my $is_first_ip_success = true;
	foreach my $ip_success (@ip_successes) {
		if (!$is_first_ip_success) {
			print ', ';
		}

		print $ip_success;

		if ($is_first_ip_success) {
			  $is_first_ip_success = false;
		}
	}
	
	print ") \n";
}

  1;
__DONE__
