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




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=$_;
}

I think your script is fine except for this line. you want to use push
to add the ip to your array. the way you're doing it your array gets
overwritten each time.

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();

-jp

.



Relevant Pages

  • Please help with convoluted script
    ... I have a script which is supposed to query a database and compile data for every ... push @months, $month; ... # Build the array which will hold the dates for the previous week ... # so we can output the proper string later. ...
    (perl.beginners)
  • Re: script input being an array of variables ... is this possible ?
    ... > will be on the host PC. ... > and then use string functions to seperate the values and iterate through ... Just post them to the script as an array, ...
    (alt.php)
  • Calling from a script to a host method that accepts params array
    ... number of arguments through 'params' array. ... Is it possible (calling from a script to a host method that accepts ...
    (microsoft.public.dotnet.framework.interop)
  • Re: script input being an array of variables ... is this possible ?
    ... How can I see how many items there are in the array? ... >> will be on the host PC. ... >> and then use string functions to seperate the values and iterate through ... > Just post them to the script as an array, ...
    (alt.php)
  • Re: Logon script - function array and select case not working
    ... this all works well, except, the function i am using for the rules in the control script causes alot of querrys to AD. as there are alot of groups. ... objTSout.writeline retrv ... So if you think that this will assign an array value to the variable, how do you think the case select statement is going go compare this array value with the literal string values such as "group name here"? ... However, by not assigning ANY value to checkgrp in the function, you are guaranteeing that, should the function ever exit, it will return no information. ...
    (microsoft.public.scripting.vbscript)