title: Differences between system function "ping" and Net::Ping module in perl?
body: <p>As I know there are two ways to find the pingable ip through the perl, which are</p>
  
  <pre><code> 1. Using system Ping Command.
   2. Using Net::Ping Module.
  </code></pre>
  
  <p>I tried to invoke the pingable state of the IP through the above two techniques. </p>
  
  <p>I am facing a problem in those methods, that is system ping command is returning true for one IP. But, the Net::Ping Module is returning false for the same IP. </p>
  
  <p>I don't know which one is correct. Anyone please advice me to prefer the right way to find a pingable IP. I have written the sample code snippet below:</p>
  
  <pre><code>#!/usr/bin/perl
  use strict;
  use Net::Ping;
  
  my $ip_address = $ARGV[0];
  chomp($ip_address);
  
  #Using Net::Ping Module
  
  my $p = Net::Ping-&gt;new();
  
  
  if ( $p-&gt;ping($ip_address) ) {
      print "Step - 1: Success!\n";
  }
  else {
      print "Step - 1: Fail!\n";
  }
  
  
  #Using System Command
  
  $retval=system("ping -c 2 $ip_address");
  
  if ($retval==0) {
      print "Step - 2: Success!\n";
  } else {
      print "Step - 2: Fail!\n";
  }
  
  print "\n\n\ Step2: $retval\n\n";
  </code></pre>
  
  <p>For some IP address system command is returning success and Net::Ping is returning fail. Is any difference between those two methods? </p>
  
  <p>Thanks,
  Madhan</p>