-----Original Message-----
From: Mazhar [mailto:[EMAIL PROTECTED] 
Sent: Thursday, June 29, 2006 12:51 PM
To: Ryan Frantz
Cc: Perl Beginners
Subject: Re: Script Required to Check a range of IP's


On 6/29/06, Ryan Frantz <[EMAIL PROTECTED]> wrote:


> -----Original Message-----
> From: Mazhar [mailto:[EMAIL PROTECTED]
> Sent: Thursday, June 29, 2006 11:44 AM
> To: Perl Beginners
> Subject: Script Required to Check a range of IP's
>
> Hi Folks,
>

> Howdy,

> 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];

You may want to check that an argument exists before proceeding.

unless ( $ARGV[0] ) {
 print "No arg!\n";
 exit;
}

> my $line;

You don't see to use this scalar; you can remove it.

> my @host_array;
>
> open(FILE,"$file_name") || die "Not been Accessed"; 

On failure, '$!' gets set.  Make sure you check for it:

open( FILE, "$file_name" ) or die "Problem opening file: $!\n";

>
> To be of more help, I'd suggest that you provide some example input.  Is
> there one address per line?  Multiple addresses per line (delimited).
>
>
> while (<FILE>) {
>   chomp;
>   @host_array=$_; 
> }
>

Since you have multiple IP addresses, you need to push them into the list or 
else the array will only have one element.

while ( <FILE> ) {
  chomp;
  push @host_array, $_;
}

Also, if it were me, I'd close the file here just to be clean.

> If we have some example input, then we can tell if the 'while' block is
> kosher.  If there are multiple IP addresses, then you'll want to 'push'
> the addresses into @host_array.
>
> ry

> 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

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


I am giving you all the sample input file...

11.1.1.1
111.1.1.1
1.111.1.1
1.1.2.3 

All the above IP's are in a new line..

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


Reply via email to