LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 02-22-2012, 12:47 AM   #1
JohnMayden
LQ Newbie
 
Registered: Sep 2011
Posts: 3

Rep: Reputation: Disabled
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
 
Old 02-22-2012, 04:12 AM   #2
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu
Posts: 1,457

Rep: Reputation: 104Reputation: 104
i can ping them with your second script. I've changed 'icmp' to 'syn'
 
Old 02-22-2012, 06:09 AM   #3
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
Try using different variable names...

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Canīt ping machines with dynamic IPīs Wurzelseppi Linux - Networking 8 05-19-2009 03:16 AM
How come I can ping between machines, but not get internet? ozymandias Linux - Networking 5 09-11-2005 05:20 PM
machines with different submasks can ping each other, why? learnfast Linux - Newbie 1 03-11-2005 10:11 AM
Cannot ping between 2 machines on same router acampbell Linux - Wireless Networking 8 02-24-2004 04:27 AM
Ping between machines triplem Linux - Networking 1 04-14-2003 06:17 PM


All times are GMT -5. The time now is 09:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration