|
Title: Help with Perl Post by: zenlakin on October 15, 2012, 02:02:51 PM 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(); " Title: Re: Help with Perl Post by: hayabusa on October 15, 2012, 02:42:56 PM A little bit modified (single class C), but try working from this:
Code: #!/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 (http://perldoc.perl.org/Net/Ping.html) ) Title: Re: Help with Perl Post by: zenlakin on October 15, 2012, 02:52:35 PM 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!!
Title: Re: Help with Perl Post by: hayabusa on October 15, 2012, 02:55:08 PM Any time! If you end up working it into something really cool, be sure to share, so others can learn from it, too!
Title: Re: Help with Perl Post by: zenlakin on October 15, 2012, 03:08:01 PM Will do!!
Powered by SMF 1.1.18 |
SMF © 2013, Simple Machines
Joomla Bridge by JoomlaHacks.com |