Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: My ping should fail but does not

by Zaxo (Archbishop)
on Jun 02, 2004 at 19:02 UTC ( #359663=note: print w/replies, xml ) Need Help??


in reply to My ping should fail but does not

You have left out the part that seems to be misbehaving. Where does pingecho() come from? What is its documented behavior? What does the code look like? It could be pinging localhost by default, which would (one hopes) return true.

You may want to consider using Net::Ping and/or DBI.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: My ping should fail but does not
by mike at rcn (Initiate) on Jun 02, 2004 at 19:56 UTC
    I was using Net::Ping; I'll update my question now.

    If I don't have a valid servername, will it default to the localhost? I didn't see anything about that in the Net-Ping-2.31 doc. . . .

      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,
      Zaxo

        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>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://359663]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2022-12-01 06:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?