Perl Ping Example Code

IT Support Forum Forums Development Perl Perl Ping Example Code

Tagged: 

Viewing 0 reply threads
  • Author
    Posts
    • #1968
      Webmaster
      Keymaster

      There are two ping commands available in Perl that I know of. I’ll share these below with a few examples…

      The first is Net::Ping. It’s not very reliable in my experience as it doesn’t work with all IP addresses very well. I know not why. Here’s an example of Net::Ping:

      use Net::Ping;
      my $p = Net::Ping->new();
      if ($p->ping(“172.16.4.58”))
      {
      print “ok\n”;
      }else{
      print “fail\n”
      }

      The next ping is System Ping. Here’s an example of the code to do a System Ping in Perl:

      $retval=system(“ping 172.16.4.58”);
      if ($retval==0)
      {
      print “OK\n”;
      } else {
      print “FAIL\n”;
      }

Viewing 0 reply threads
  • You must be logged in to reply to this topic.