#!/usr/bin/perl -wT
use Socket;

print "Content-type: text/html\n\n";
open(MYINPUTFILE, "<ct.txt");
while(<MYINPUTFILE>)
{
 # Good practice to store $_ value because
 # subsequent operations may change it.
 my($line) = $_;

 # Good practice to always strip the trailing
 # newline from the line.
 chomp($line);

 # Print the line to the screen and add a newline
 $l2 = $line + 1;
}
#print header(-cookie=>[$cookie1,$cookie2]);

close(MYINPUTFILE);


printf "%06d", $l2;


open(MYINPUTFILE, ">ct.txt");
print MYINPUTFILE "$l2";
close(MYINPUTFILE);


open(MYINPUTFILE, "<full.txt");
my @str = <MYINPUTFILE>;
$lcnt = scalar(@str);
close(MYINPUTFILE);
 
if ($lcnt > 30)
{
   open(MYINPUTFILE, ">full.txt");
   $lcnt = 1;
}
else
{
   open(MYINPUTFILE, ">>full.txt");
}

print MYINPUTFILE "\n$lcnt  $l2 ";
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
printf MYINPUTFILE "%4d-%02d-%02d %02d:%02d:%02d", 
$year+1900,$mon+1,$mday,$hour,$min,$sec;


my $ip = $ENV{'REMOTE_ADDR'};
print MYINPUTFILE "  -    $ip  ";

#my $here = $ENV{'REQEST_URI'};
#my $rh = $ENV{'REMOTE_HOST'};
#my @digits = split (/\./,$ip);
#my $address = pack ("C4", @digits);
#my $host = gethostbyaddr ($ip, AF_INET);

$name    = gethostbyaddr(inet_aton($ip), AF_INET)
                or die "Can't look up $address : $!\n";

print MYINPUTFILE "  -   $name ";
close(MYINPUTFILE);

