in reply to Re: Re: My ping should fail but does not
in thread My ping should fail but does not

Ok, pingecho() is a deprecated back-compat wrapper for the ping method of Net::Ping. Running perldoc -m Net::Ping shows that ping returns an empty list if no $host is given. The default I mentioned was pure speculation. I don't see any way that an empty host string will return true, unless your inet_aton does so for empty argument.

Try distinguishing between undef and 0 as return values for pingecho. It is supposed to return undef for an unresolved host and 0 for an unreachable one. That will help you diagnose the problem.

How about just skipping the ping if the host string is not true?

if ($host) { if (pingecho($host,$timeout)) { #... } }

After Compline,

Replies are listed 'Best First'.
Re^4: My ping should fail but does not
by mike at rcn (Initiate) on Jun 04, 2004 at 14:29 UTC
    Thanks Both:

    I've been trying your suggestion and different variations on it, and am not having much luck.

    In the office, with high-speed connectivity, it generally seems to work as long as the $timeout value is high enough (something above 20), but not always. Sometimes, the ping just seems to die, with no return to the program. (In the office, a stand-alone ping usually shows about 10 ms turnaround.)

    Working at home, with 56 kbps dial-up, it has died every time so far. But, here, the stand-alone ping is about 160 - 180 ms. I then raised the $timeout value to 900, but it still died within the ping. The code, results and stand-alone ping are shown below.

    Is there something better than ping for determining connectivity to a remote host? As always, your help and insights are very much appreciated!!

    use Net::Ping; # Global variables my $timeout = 90; # Time to wait for a response from ping # Part of sub -- printf "DB Server to be tested for accessibility: $dbSrvrBox\n\n"; # Ensure the connection to the DB Server is available if (!$dbSrvrBox) { printf ("Cannot find a boxname value in \"$_\" - Will abe +nd.\n\n"); # 2 }; next if (!$dbSrvrBox); printf "Ready to ping $dbSrvrBox\n\n"; if (ping($dbSrvrBox, $timeout)) { printf "DB Server ($dbSrvrBox) is accessible at startup. +\n\n"; &msgLog ("DB Server ($dbSrvrBox) is accessible at startup. +\n"); } else { printf ("Cannot access $dbSrvrBox - abending.\n\n"); + # 3 }; printf "After ping\n"; RESULTS (DOS Cmd window) -- DBSERVER0: \\PLYSDEV03\DEV03- DB Server to be tested for accessibility: PLYSDEV03 Ready to ping PLYSDEV03 C:\A_DRS_Proj\PerlCoding> STAND-ALONE PING -- C:\A_DRS_Proj\PerlCoding>ping PLYSDEV03 Pinging PLYSDEV03 [ ip ] with 32 bytes of data: Reply from [ ip ]: bytes=32 time=180ms TTL=125 Reply from [ ip ]: bytes=32 time=160ms TTL=125 Reply from [ ip ]: bytes=32 time=160ms TTL=125 Reply from [ ip ]: bytes=32 time=170ms TTL=125 Ping statistics for [ ip ]: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 160ms, Maximum = 180ms, Average = 167ms C:\A_DRS_Proj\PerlCoding>