Perl, Ping Multiple Machines.

Hi everyone, hope all is well.

Im really struggling with Perl to ping more than one computer. I've tried with this
Code:
use Net::Ping;

my $ip = 'xx.yyy.237.50';
my $ping = Net::Ping->new( "icmp", 1, 64);
	if ( $ping->ping($ip) ) {
		print "$ip answered\n";
		}
		else {
			print "$ip did not answer\n";
		      }

Which works no problems, however say if I want to ping two machines, what would I have to do? I was thinking something like

Code:
use Net::Ping;

@ip = qw (xx.yyy.237.50 aa.bb.161.34);
my $ping = Net::Ping->new("icmp", 5);

if ($ping->ping($ip[0], $ip[1])) {
	print "$ip[0], $ip[1], are reachable";
}
which obviously doesn't work!
Any help would be greatly appreciated. Im extremely new to Perl, just trying to get a hang of it. Thanks in advance.
 
Code:
my @ip = ("xx.yyy.237.50", "aa.bb.161.34");

foreach my $host ( @ip ) {
   myping( $host );
}
 
Back
Top