# Perl, Ping Multiple Machines.



## hali (Feb 22, 2012)

Hi everyone, hope all is well.

Im really struggling with Perl to ping more than one computer.  I've tried with this 

```
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 


```
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.


----------



## SirDice (Feb 22, 2012)

```
my @ip = ("xx.yyy.237.50", "aa.bb.161.34");

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


----------

