RE: Script Required to Check a range of IP's



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>


.



Relevant Pages

  • Re: $1 $2 var confusion
    ... I have strict and warnings enabled. ... until the end of the enclosing block or until the next successful match, ... it becomes undefined as there are no capturing parentheses. ... unless ($host eq 'domain.com') { ...
    (perl.beginners)
  • Re: Script Required to Check a range of IPs
    ... Input File --- test.txt ... use strict; ... use warnings; ... print "$host not reachable.\n"; ...
    (perl.beginners)
  • Re: connecting to multiple hosts using Net::SSH2
    ... # (or to steal a routine from it) it'll be much easier to read ... use strict; ... # setup new connection in an OO sort of way: ... There's a few ways to feed in the list of hosts you want to use to hit all the boxes in a host list and execute your command. ...
    (perl.beginners)
  • Re: Script Required to Check a range of IPs
    ... use strict; ... Why is the die string in double quotes? ... What aren't you putting the reason it failed in the string? ... chomp $host; ...
    (perl.beginners)
  • Re: Virtual mail backscatter
    ... stricter spam fitering and so bouncing back emails that I have let ... The answer is to make your spam-scanning on the MX host as strict as ...
    (comp.mail.sendmail)