RE: Script Required to Check a range of IP's
- From: ryanfrantz@xxxxxxxxxxxxxxxx (Ryan Frantz)
- Date: Thu, 29 Jun 2006 15:41:05 -0400
Here's the same thing but "Perl Best Practice" ified a bit:$!";
#!/usr/bin/perl
use strict;
use wanrings;
use Net::Ping;
die 'Please give me a filename as my argument!' if !defined $ARGV[0];
open(my $ipfile_fh, '<', $ARGV[0]) || die "Could not open $ARGV[0]:
my $icmp = Net::Ping->new('icmp');
while(<$ipfile_fh>) {
chomp $host;
I've only peeked inside my newly purchased 'Perl Best Practices' book,
but I'm willing to bet that there is a section on declaring/scoping
variables ;).
$host wasn't previously declared in any context so the 'strict' pragma
is gonna complain. For every instance of $host in _this_ example,
replace it with Perl's favorite: $_.
ry
if( $icmp->ping($host, 2) ) {
print "$host is alive! weeeee\n";
}
else {
print "$host is dead. boooo\n";
}
sleep 1;
}
$icmp->close();
close $ipfile_fh;
--
To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx
<http://learn.perl.org/> <http://learn.perl.org/first-response>
.
- Prev by Date: Re: Script Required to Check a range of IP's
- Next by Date: Crypt::GPG won't decrypt file
- Previous by thread: RE: Script Required to Check a range of IP's
- Next by thread: regexp pattern matching
- Index(es):
Relevant Pages
|