you might have seen my other ping script which doesn't use any ping module,but here i use the Ping::External module which offers me some extra features like timeout,count and size.i used one file handle which you can dump all your ips in the textfile called ip.txt so, you can put n no of ips in the file to check the reachability.The output is writes to the output.txt
you can download this module at http://search.cpan.org/~chorny/Net-Ping-External-0.13/External.pm and you can install this by untaring to a particular folder and open prompt and goto that folder and type these following commads.
"make install"
"perl test.pl"
you can also find the installation instructions of this module in the above link itself at the end of the page
#!/usr/bin/perl -w
use Net::Ping::External qw(ping);
open(IP,"ip.txt");
open(OUTPUT,">output.txt");
$count=0;
while(<IP>)
{
$ip=$_;
chomp($ip);
my $alive = ping(host => "$ip",count=>2,size=>1024,timeout=>3);
if ($alive)
{
print OUTPUT "$ip is online\n";
print "$ip is online\n" ;
}
else
{
print OUTPUT "$ip is offline\n";
print "$ip is offline\n";
}
}$count++;
close(IP);
close(OUTPUT);
you can download this module at http://search.cpan.org/~chorny/Net-Ping-External-0.13/External.pm and you can install this by untaring to a particular folder and open prompt and goto that folder and type these following commads.
"make install"
"perl test.pl"
you can also find the installation instructions of this module in the above link itself at the end of the page
use Net::Ping::External qw(ping);
open(IP,"ip.txt");
open(OUTPUT,">output.txt");
$count=0;
while(<IP>)
{
$ip=$_;
chomp($ip);
my $alive = ping(host => "$ip",count=>2,size=>1024,timeout=>3);
if ($alive)
{
print OUTPUT "$ip is online\n";
print "$ip is online\n" ;
}
else
{
print OUTPUT "$ip is offline\n";
print "$ip is offline\n";
}
}$count++;
close(IP);
close(OUTPUT);
No comments:
Post a Comment