Thursday, June 30, 2011

PING TEST

Hi all...
The following program initiates ping and write it to a file whether it is reachable or not..
It takes input from a input file "input.txt",create input.txt and paste all your ip's here and run it, an output.txt automatically created and writes the output to it whether it is reachable or not..

NOTE:I hope you know how to run this code in "windows" and "linux"

PROGRAM:

open(INPUT,"input.txt") or die "couldn't open input.txt";
open(OUTPUT,">output.txt") or die "couldn't open input.txt";
$a=0;
print OUTPUT "IP,STATUS\n";
while(<INPUT>)
{
chomp($_);
$url=($_);
$ping = `ping $url`;

print "$ping";
if ($ping =~ m/Request timed out/)
{
#print "$ping";
print OUTPUT "$url,unreachable\n";

}
else
{

#print "$ping";
print OUTPUT "$url,reachable\n";

}
$a++;
}
close INPUT;
close OUTPUT;

No comments:

Post a Comment