Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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!

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1080574]
Front-paged by Arunbear
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2018-02-23 12:55 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (302 votes). Check out past polls.