Hello g_speran,

You can simply follow the example of the perldoc Net::Ping with valid IP address.

You do not need to use icmp unless you are root (unnecessary) you can use tcp and also you do not need if(){}else{} follow the example documented.

Sample of code:

#!/usr/bin/perl use strict; use warnings; use Net::Ping; my @host_array = ("127.0.0.1", "10.0.0.10"); my $p = Net::Ping->new("tcp"); # $p->bind($my_addr); # Specify source interface of pings foreach my $host (@host_array) { print "$host is "; print "NOT " unless $p->ping($host, 2); print "reachable.\n"; sleep(1); } $p->close(); __END__ $ perl test.pl 127.0.0.1 is reachable. 10.0.0.10 is NOT reachable.

Update: In case you want to know with precision on the ping time you can use this approach (similar to documentation):

#!/usr/bin/perl use strict; use warnings; use Net::Ping; my @host_array = ('localhost', '10.0.0.10'); # High precision syntax (requires Time::HiRes) my $p = Net::Ping->new(); $p->hires(); foreach my $host (@host_array) { my ($ret, $duration, $ip) = $p->ping($host, 2); if ($ret) { printf("$host [ip: $ip] is alive (packet return time: %.2f ms)\n", 1000 * $duration); } else { printf("$host [ip: $ip] is not alive (packet return time: %.2f ms) +\n", 1000 * $duration); } sleep(1); } $p->close(); __END__ $ perl test.pl localhost [ip: 127.0.0.1] is alive (packet return time: 0.11 ms) 10.0.0.10 [ip: 10.0.0.10] is not alive (packet return time: 2002.36 ms +)

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re: Net::Ping 2.63 Failing by thanos1983
in thread Net::Ping 2.63 Failing by g_speran

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.