Skip to content
This repository has been archived by the owner on Mar 30, 2020. It is now read-only.

Commit

Permalink
Silly laptop doesn't like the ANY-type.
Browse files Browse the repository at this point in the history
  • Loading branch information
skx committed Jul 4, 2014
1 parent 764bdf4 commit c987fb0
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions multi-ping
Expand Up @@ -125,36 +125,41 @@ sub pingHost
# Lookup the IP for the name specified
#
my $res = Net::DNS::Resolver->new;
my $query = $res->query( $hostname, "ANY" );

if ($query)
#
# The two types we'll lookup.
#
# NOTE: This shouldn't be required but my laptop resolver seems to
# struggle with lookups of the type "ANY". Sigh.
#
#
foreach my $type (qw! A AAAA !)
{
foreach my $rr ( $query->answer )
my $query = $res->query( $hostname, $type );

if ($query)
{
my $ping_binary =
$rr->type eq "A" ? "ping" :
$rr->type eq "AAAA" ? "ping6" :
"";
if ($ping_binary)
foreach my $rr ( $query->answer )
{
if (
system(
"$ping_binary -c1 -w$timeout -W$timeout $hostname >/dev/null 2>/dev/null"
) == 0
)
{
print "Host $hostname - " . $rr->address() . " alive\n";
}
else
my $ping_binary =
$rr->type eq "A" ? "ping" :
$rr->type eq "AAAA" ? "ping6" :
"";
if ($ping_binary)
{
print "Host $hostname - " . $rr->address() . " FAILED\n";
my $result = system(
"$ping_binary -c1 -w$timeout -W$timeout $hostname >/dev/null 2>/dev/null"
);

print "Host $hostname - " . $rr->address() .
( ( $result == 0 ) ? " - alive" : " - FAILED" ) . "\n";
}
}
}
}
else
{
print "WARNING: Failed to resolve $hostname\n";
else
{
print "WARNING: Failed to resolve $hostname [$type]\n";
}
}
}

Expand Down

0 comments on commit c987fb0

Please sign in to comment.