From 6b666d62660456cd8ad7e1562c7d8dde8742c75e Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Fri, 1 Mar 2013 17:54:03 -0500 Subject: [PATCH] Show Status Difference With Symbol Add the -p switch to show the difference between reachable and unreachable destinations. This allows outputting to a text file while still being able to distinguish between the status of IP address when the -a switch is used. --- sbin/pinger | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sbin/pinger b/sbin/pinger index 32a1aaa..b33d52f 100755 --- a/sbin/pinger +++ b/sbin/pinger @@ -15,10 +15,10 @@ $| = 1; die("pinger must be run as root\n") if($> != 0); my $alive = 1; -my(%switches, $all, $both, $time, $name, $force, $startTime, $finishTime); +my(%switches, $all, $print, $both, $time, $name, $force, $startTime, $finishTime); # handle command line options -my $status = getopts('abdfrnth', \%switches); +my $status = getopts('abdfrnpth', \%switches); help() if(!$status || $switches{'h'}); for (keys %switches) { switch($_) { @@ -26,6 +26,7 @@ for (keys %switches) { case 'b' { $both = 1; $name = 1; } case 'd' { $alive = 0; } case 'f' { $force = 1; } + case 'p' { $print = 1; } case 'r' { $alive = 1; } case 'n' { $name = 1; } case 't' { $time = 1; } @@ -79,6 +80,10 @@ for(my $i = $start, my $k = 1; $i <= $end; $i++, $k++) { } } + if($print) { + $ip = ($reachable) ? "o $ip" : "x $ip"; + } + if($reachable) { push(@reachable_ips, colored($ip, 'green')); } else { @@ -155,6 +160,7 @@ sub help { print "\t-d\t\tList dead addresses\n"; print "\t-f\t\tForce hostname lookup even if unreachable\n"; print "\t-n\t\tReturn list as hostnames when possible\n"; + print "\t-p\t\tEnable print mode; only noticeable with -a enabled\n"; print "\t-r\t\tList reachable addresses (default)\n"; print "\t-t\t\tTime ping execution\n"; exit(1);