Help with Perl

Viewing 4 reply threads
  • Author
    Posts
    • #7962
      zenlakin
      Participant

      Hello all. I am trying to mess with Perl a bit and am trying to put together a ping script but for some reason I am not getting the desired result. I just want to come up with a simple scrip that will ping a range of IP addresses and tell me if they are active or not. Below is what I have come up with so far but to no avail.

      “#!/usr/bin/perl

      use Net::Ping;

      $p = Net::Ping->new(“icmp”);
      $host = “192.168.xx.xx”;
      @range = (1 .. 255);
      foreach $host (@range)
      {
      print “$host is dead.n”
      unless $p->ping($host);
      }
      $p->close();

    • #50481
      hayabusa
      Participant

      A little bit modified (single class C), but try working from this:

      #!/usr/bin/perl

      use Net::Ping;
         $my_addr='192.168.26.100';
         $p = Net::Ping->new("icmp");
         $p->bind($my_addr); # Specify source interface of pings
         @host_array=(1 .. 255);
         foreach $host (@host_array)
         {
             $ip="192.168.26.$host";
             print "$ip is ";
             print "NOT " unless $p->ping($ip, 2);
             print "reachable.n";
             sleep(1);
         }
         $p->close();

      The bind interface helped, as well as a need to clearly define the host you were after.

      Hope that helps.

      (Edit-
      You can get a better feel for the Net::Ping from the docs:
      http://perldoc.perl.org/Net/Ping.html )

    • #50482
      zenlakin
      Participant

      Ahh I see now. Initially when I was playing with the bind syntax I was using double quotes instead os single quotes which explains why it wouldn’t run. I will modify my other script that I had using bind and try it again. Thanks!!

    • #50483
      hayabusa
      Participant

      Any time!  If you end up working it into something really cool, be sure to share, so others can learn from it, too!

    • #50484
      zenlakin
      Participant

      Will do!!

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

Copyright ©2021 Caendra, Inc.

Contact Us

Thoughts, suggestions, issues? Send us an email, and we'll get back to you.

Sending

Sign in with Caendra

Forgot password?Sign up

Forgot your details?