http://www.perlmonks.org?node_id=1080574

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!

Replies are listed 'Best First'.
Re: Using Ping with perl
by NetWallah (Canon) 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.