1
0
Fork 0

Force Hostname Lookup

By default, pinger will not lookup hostnames for IPs that are
unreachable.  This prevents extended times if dead IPs do not have host
entries.  However, there are also cases where DNS resolution is
important even when the IP is unreachable.  pinger now supports this
using the -f flag.
This commit is contained in:
Andrew Tomaka 2013-02-28 07:56:40 -05:00
parent d744edf83f
commit e0e789b58f
1 changed files with 5 additions and 3 deletions

View File

@ -14,14 +14,15 @@ $| = 1;
die("pinger must be run as root\n") if($> != 0);
my $alive = 1;
my(%switches, $time, $name, $startTime, $finishTime);
my(%switches, $time, $name, $force, $startTime, $finishTime);
# handle command line options
my $status = getopts('drnth', \%switches);
my $status = getopts('dfrnth', \%switches);
help() if(!$status || $switches{'h'});
for (keys %switches) {
switch($_) {
case 'd' { $alive = 0; }
case 'f' { $force = 1; }
case 'r' { $alive = 1; }
case 'n' { $name = 1; }
case 't' { $time = 1; }
@ -69,7 +70,7 @@ for(my $i = $start, my $k = 1; $i <= $end; $i++, $k++) {
my $reachable = $p->ping($ip, 1);
if($reachable == $alive) {
if($name && $reachable) {
if($name && ($reachable || $force)) {
my $hostaddr = gethostbyaddr(inet_aton($ip), AF_INET);
$ip = $hostaddr if($hostaddr ne "");
}
@ -128,6 +129,7 @@ sub progressBar {
sub help {
print "usage:\t pinger [-d] start [finish]\n\n";
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-r\t\tList reachable addresses (default)\n";
print "\t-t\t\tTime ping execution\n";