LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Ping Multiple Machines in Perl (https://www.linuxquestions.org/questions/programming-9/ping-multiple-machines-in-perl-930623/)

JohnMayden 02-21-2012 11:47 PM

Ping Multiple Machines in Perl
 
Evening Gents!
Im having a little trouble with a perl script to ping multiple machines. I can ping one easily enough with


use Net::Ping;

my $ip = '724.125.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";
}

But i cant seem to ping multiple machines, i've tried something like.

use Net::Ping;

my @ip = qw(74.125.237.48 74.125.237.51 123.123.123.123);
my $ping = Net::Ping->new("icmp", 5);

foreach $ip (@ip){
$ping->ping($ip);
print "$ip answered\n";
sleep(1);
}

But obviously this isnt working!
Any help would be great peeps

Thanks

j-ray 02-22-2012 03:12 AM

i can ping them with your second script. I've changed 'icmp' to 'syn'

Cedrik 02-22-2012 05:09 AM

Try using different variable names...

I mean for ips list, use @ips and $ip for each ip


All times are GMT -5. The time now is 04:13 AM.