Re: Script Required to Check a range of IP's
- From: syedmazhar.hasan@xxxxxxxxx (Mazhar)
- Date: Thu, 29 Jun 2006 22:38:48 +0400
Thanks Prabhu,
Your script works!!!!
Regards
Mazhar
On 6/29/06, Prabu <prabu.ayyappan@xxxxxxxxx> wrote:
Hello,
Hope this is what you need
Input File --- test.txt
172.16.1.194
172.16.1.20
172.16.1.200
172.16.1.34
Program to check active or not -- pingpro.pl
#!/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" ;
@host_array=<FILE>;
close(FILE);
my $p = Net::Ping->new("icmp");
foreach my $host(@host_array)
{
if($p->ping($host, 2))
{
chomp($host);
print "$host is alive.\n";
}
else
{
chomp($host);
print "$host not reachable.\n";
}
sleep(1);
}
$p->close();
close (FILE);
How to run -- perl pingpro.pl test.txt
Output
172.16.1.194 is alive.
172.16.1.20 is alive.
172.16.1.200 is alive.
172.16.1.34 not reachable.
--
Prabu.M.A
When I was born I was so surprised
I didnt talk for a period and half
-Gracie Allen
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";
>
> while (<FILE>) {
> chomp;
> @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
>
- Follow-Ups:
- Re: Script Required to Check a range of IP's
- From: JupiterHost.Net
- Re: Script Required to Check a range of IP's
- References:
- Script Required to Check a range of IP's
- From: Mazhar
- Re: Script Required to Check a range of IP's
- From: Prabu
- Script Required to Check a range of IP's
- Prev by Date: Re: regexp pattern matching
- Next by Date: Re: Windows XP ppm and perldoc problems
- Previous by thread: Re: Script Required to Check a range of IP's
- Next by thread: Re: Script Required to Check a range of IP's
- Index(es):
Relevant Pages
|