Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Using Ping with perl

by Katnopic (Initiate)
on Apr 01, 2014 at 14:24 UTC ( #1080574=perlquestion: print w/ replies, xml ) Need Help??
Katnopic has asked for the wisdom of the Perl Monks concerning the following question:

Hi everybody! I am new to perl, and i've got a task to simulate the tracert command (from windows) in perl code. i've tried "cheating" by using qx(ping -i n) but ping doesnt give me the ms, which i need. To the subject, i've been messing around abit with the Net::Ping module but i've had a hard time understanding how to use it. I wanna know if there's a way with this module to achieve what i want, which is pinging with a different ttl each time until i reach the destination address, and getting the ms of each ping. Thanks!

Comment on Using Ping with perl
Re: Using Ping with perl
by NetWallah (Abbot) on Apr 01, 2014 at 14:43 UTC
    Here are the basics of Net::Ping (Pieces extracted from old code):
    # Assumes $host is set to what you want to ping my $p = Net::Ping->new("icmp",$TimeOut,,,$ttl); $p->hires(1);#use Time::HiRes module, allowing milliseconds to be +returned by subsequent calls to ping(). my ($ret, $duration, $ip) = $p->ping($host); if ($ret){ $verbose and printf("$host [ip: $ip] is alive (%.2f ms)\n" +, 1000 * $duration); } $p->close();

            What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?
                  -Larry Wall, 1992

      If you want to simulate traceroute, have you tried looking how it's done in Net::Traceroute::PurePerl. Unfortunately, it's not as straightforward as your code hopes.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1080574]
Front-paged by Arunbear
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 2014-08-21 03:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (127 votes), past polls