We help IT Professionals succeed at work.

PING module

Pampa
Pampa asked
on
I'am using use Net::Ping to verify if some servers are alive.

The procedure is the following:
 my ($IPsite,$timeout)=@_;
 my $p = Net::Ping->new('icmp',$timeout);
 unless (defined $p) { print "NO pude crear  Net::Ping";}
        if ($p->ping($IPsite)) {
            $res= "T";
        }else{
             $res = "F";
        }
       $p->close;
return $res;

#################################################

All works fine except for one thing, I can`t detect if the server answer 1,2,3 of the 4 packets send by the PING command.

I mean, I have a place that loose 10% of the packets I send to him, I wan`t to detect that problem......

As I'am doing now, sometimes the result of the ping is true and sometimes is False....
So if it false I make the ping "AGAIN", but this action doesn`t mean that I can detect the problem I mention before...

Any ideas of how can I detect this kind of problem.?


Thanks,
Fernando
Comment
Watch Question

Commented:
you could try running the OS's ping command by placing the command in `ping 0.0.0.0` and placing the return in a variable and analising the return, eg;

my $var = `/anypath/ping 0.0.0.0`;

from here you could do a series of pattern matching to extract the information you want to view.

Hope this helps, if I have the wrong end of the stick let me know and I will have another go.
$p->ping($IPSite)
will send one ping packet. You can add a loop to have successive pings, like this:

my $p = Net::Ping->new("icmp",$timeout);
unless (defined $p) { print "NO pude crear  Net::Ping";}
  $tryping=0;
  $res_success=0;
  $res_fail=0;
  while ($tryping < 10) {
       $tryping++;
       if ($p->ping($IPSite)) {
           $res_success++;
       }else{
            $res_fail++;
       }
}
print "Succes: $res_success\nFail: $res_fail\n";

I hope this helps.
dirk

Author

Commented:
I will accept your comment because came first tahn the others....
Thanks all

Explore More ContentExplore courses, solutions, and other research materials related to this topic.