nick has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I am writing a script that needs to occasionally ping hosts. This script needs to be able to run on mosts unix platforms, and so I am using Net::Ping (instead of dealing with the different command line pings).

The only problem is, when a ping is successful, I'd like to get the output of the ping, ie: 64 bytes from 127.0.0.1: icmp_seq=0 ttl=247 time=0.0 ms Net::Ping only returns true if successful or 0 if failed. Is there any way I can get the statistics of the ping without resorting to the command line ping?

- Nick

Replies are listed 'Best First'.
Re: getting ping output using Net::Ping
by traveler (Parson) on Dec 18, 2001 at 05:00 UTC
    There are five parts to the output:
    1. Number of bytes sent
    2. host to contact
    3. sequence number
    4. ttl
    5. time it took
    You can set the first two when you call Net::Ping so those are known. You can compute number 5 roughly by timing the call to ping. Number 3 is mostly to tell you about lost and out of order packets -- it is not returned by Net::Ping nor is number 4. What info do you really need?

    HTH, --traveler

      I guess the important bit is #5. I'd like be able to say it took X ms. How do I time a call to a method? I have never done that before.
      - Nick
      
        use Time::HiRes 'time'; my $before=time(); #do stuff here my $after=time(); my $howlong=$after-$before;
        Note, however, that Time::HiRes returns the time in floating-point seconds, not milliseconds.

        =cut
        --Brent Dax
        There is no sig.