Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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 192.168.1.150 (192.168.1.150) 56(84) bytes of data. 64 bytes from 192.168.1.150: icmp_req=1 ttl=254 time=7.34 ms 64 bytes from 192.168.1.150: icmp_req=2 ttl=254 time=2.11 ms 64 bytes from 192.168.1.150: icmp_req=3 ttl=254 time=2.04 ms 64 bytes from 192.168.1.150: icmp_req=4 ttl=254 time=2.16 ms ^C --- 192.168.1.150 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 (Prior) 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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (14)
As of 2015-07-07 14:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (89 votes), past polls