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



On Thu, 2006-29-06 at 19:44 +0400, Mazhar wrote:
Hi Folks,

I have a requirement of writing down a script to check the range of IP's in
a text file and display them which all are active and not active.

I have written down the below and needs your help because it is not giving
me the correct ouptut.

################################################################
#!/usr/bin/perl

use strict;
use warnings;
use Net::Ping;

my $file_name=$ARGV[0];
my $line;
my @host_array;

open(FILE,"$file_name") || die "Not been Accessed";

# Recommend you put the file name in the die statement.
# It comes from the command line and may contains typos.

open( FILE, "< $file_name" ) || die "Not been Accessed $file_name:
$!";

# Also recommend use of '<' for tainted file names.
# What if someone tried: my_script 'cat /etc/passwd- |'



while (<FILE>) {
chomp;
@host_array=$_;

# This will record the last line in the array.
# Use push instead; see `perldoc -f push`

push @host_array, $_;


}

my $p = Net::Ping->new();
foreach my $host (@host_array)
{
print "$host is ";
print "NOT " unless $p->ping($host, 2);
print "reachable.\n";
sleep(1);
}
$p->close();

close (FILE);

###########################################################

Needs your help on the above

Regards
Mazhar


--
__END__

Just my 0.00000002 million dollars worth,
--- Shawn

"For the things we have to learn before we can do them, we learn by doing them."
Aristotle

* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is at http://perldoc.perl.org/


.



Relevant Pages

  • Patch push programs for Win2K domain world?
    ... query the server itself along with domain hosts for needed patches to push. ... patch to a host, wait for the host to shutdown, reboot, and continue ...
    (microsoft.public.security)
  • Patch push programs for Win2K domain world?
    ... query the server itself along with domain hosts for needed patches to push. ... patch to a host, wait for the host to shutdown, reboot, and continue ...
    (microsoft.public.win2000.security)
  • Re: New Collector Needs Advice
    ... postings. ... If I could please push my luck and ask one more question: ... If possible I always recommend trying your local dealers first. ...
    (rec.collecting.coins)
  • Re: ordinal logics and Diophantine equations
    ... H. Enderton wrote: ... | If you want to push further on this, I recommend ... | looking up Feferman's work on transfinite progressions ...
    (sci.math)
  • RE: If I press Save instead of Save as wheres my file?
    ... it will go to a temporaty file, to see the root I recommend you to open ... another email with attachment, first save it, then push save as an writte the ...
    (microsoft.public.excel.misc)