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



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
>





Relevant Pages

  • Re: Really Baffled any clues as to what is going on?
    ... > I am working on a script, it has an input file of machine names. ... > Dim fstrLogFilePath ... > fstrInputFile = InputBox("Enter name of file containing machines to ...
    (microsoft.public.scripting.vbscript)
  • Re: internet proxy
    ... Is it possible to create separate shortcuts to IE - one with 'proxy server ... This script gets used when you enable the "Automatically ... connect to the host so no proxy would get used. ...
    (microsoft.public.windowsxp.general)
  • Re: Parse an input file using a Key value
    ... I have an input file in the following format getting repeated. ... I tried to achieve this task using the following script below but it is ... To tranpose certain rows into columns and sort by one of the ...
    (comp.unix.shell)
  • Re: Running a DOS program using Microsoft Command Shell
    ... needed are available by public FTP: ... and the input file is run.txt. ... missing the ESC character, since I don'y know how to feed ESC in this ... When instructed from shell script, the progam simply ignores all SendKeys. ...
    (microsoft.public.windows.server.scripting)
  • Re: How do I insert a cgi script into Publisher page?
    ... is not where I host my website. ... If your ISP supports cgi and has a form handling program then a form ... You must tell the server what e mail address you want the form results ... any where else you so desire or an auto redirect script with a delay. ...
    (microsoft.public.publisher.webdesign)