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/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>