Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Net::Ping output

by gaurav (Acolyte)
on Aug 19, 2013 at 04:25 UTC ( #1049967=perlquestion: print w/ replies, xml ) Need Help??
gaurav has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am very new to Perl , I have one question regarding Net::Ping output.But before that , I want to show the system ping output on linux system

PING ( 56(84) bytes of data. 64 bytes from icmp_req=1 ttl=254 time=7.34 ms 64 bytes from icmp_req=2 ttl=254 time=2.11 ms 64 bytes from icmp_req=3 ttl=254 time=2.04 ms 64 bytes from icmp_req=4 ttl=254 time=2.16 ms ^C --- ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3003ms rtt min/avg/max/mdev = 2.043/3.415/7.342/2.268 ms

My question is that can we get this type output by using Net::Ping module of perl , because I have to parse this output according to our requirement . I have done a lot of searching regarding this but have not found any thing. So please enlighten me on this.Thanks in advance

Comment on Net::Ping output
Download Code
Re: Net::Ping output
by vinoth.ree (Parson) on Aug 19, 2013 at 05:22 UTC

    Hi gaurav

    To get the same output execute the `ping` command with ``(backtick) or qx() and capture the output use regex and parse whatever you want.

    use ping -c option to quit the ping command automatically, not with control-C

    All is well

      Hi , Thanks for your reply,but if I am not wrong,are you talking about system ping command ?

        Yes, You are trying to ping particular host right ?

        All is well
Re: Net::Ping output
by Anonymous Monk on Aug 19, 2013 at 11:59 UTC
    Net::Ping does not generate any output by itself, but you should be able to calculate any values you need yourself. From the POD:
    # High precision syntax (requires Time::HiRes) $p = Net::Ping->new(); $p->hires(); ($ret, $duration, $ip) = $p->ping($host, 5.5); printf("$host [ip: $ip] is alive (packet return time: %.2f ms)\n", + 1000 * $duration) if $ret; $p->close();
    Do you need help in making a basic pinging loop, or calculating minimum, maximum, average, standard deviation? Or finding the host's reverse DNS?

      Actually I want the same output as System-Ping command say, Tx packet,Rx Packets,TTL,RTT(max,min,avg),packet-loss.

        And you can get the same output. Ping n times, collect results in an array, calculate values, print them out (if necessary). Which part were you having trouble with?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1049967]
Approved by vinoth.ree
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2014-08-01 22:49 GMT
Find Nodes?
    Voting Booth?

    Who would be the most fun to work for?

    Results (51 votes), past polls