Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

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
Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1080574]
Front-paged by Arunbear
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2015-11-26 19:26 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (706 votes), past polls