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;

Friday, June 17, 2011

Copy data from one file to another file

This is my first program which Copies data from log.txt file to log1.txt.
Program 1:

open (LOGFILE, "log.txt") or die "I couldn't get at log.txt";
open (ABC,">log1.txt");
for $line(<LOGFILE>)
{

print ABC "$line";
}


output:this program copies all the data from log.txt to log1.txt