#!/usr/bin/perl # tell the web browser we're going to send it HTML text it needs to process # instead of plain text which it can display without processing print "Content-Type: text/html\n\n"; # variables $debug = 0; $linenumber = 0; $error = 0; $whois_server = 0; $current_max_server = 6; # whois server definitions # 0 = arin.net # 1 = dnsstuff.com # 2 = zoneedit.com # 3 = ripe.net # 4 = apnic.net # 5 = lacnic.net # 6 = afrinic.net # http://remote.12dt.com/rns/ # http://www.dnsstuff.com/ # http://www.dnsstuff.com/tools/ptr.ch?ip=+209.16.217.15+ # http://www.zoneedit.com/lookup.html?ipaddress=209.16.217.15&server=&reverse=Look+it+up # http://www.ripe.net/fcgi-bin/whois?form_type=simple&full_query_string=&searchtext=194.140.65.241&submit.x=9&submit.y=9&submit=Search # http://apnic.net/apnic-bin/whois.pl?searchtext=211.0.0.0&whois=Go # http://lacnic.net/cgi-bin/lacnic/whois?lg=EN&query=24.99.119.99 # http://www.afrinic.net/cgi-bin/whois?form_type=simple&full_query_string=&searchtext=82.201.209.19 @servers = ("arin.net", "dnsstuff.com", "zoneedit.com", "ripe.net", "apnic.net", "lacnic.net", "afrinic.net"); $my_server = "http://robertdell.dyndns.org/"; $my_cgi_name = "cgi-bin/getaccesslog.cgi"; if ($ENV{'REQUEST_METHOD'} eq 'GET') { # Split the name-value pairs @pairs = split(/&/, $ENV{'QUERY_STRING'}); } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { # Get the input read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # Split the name-value pairs @pairs = split(/&/, $buffer); } else { }; foreach $pair (@pairs) { # Split the pair up into individual variables. # local($name, $value) = split(/=/, $pair); # Decode the form encoding on the name and value variables. # # v1.92: remove null bytes # $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $name =~ tr/\0//d; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/\0//d; if ($name eq "method") { $whois_server = $value; if ($whois_server < 0) { $whois_server = 0; } elsif ($whois_server > $current_max_server) { $whois_server = 0; }; }; }; # refresh how often? $refresh_hours = 0; $refresh_minutes = 6; $refresh_seconds = 0; $refreshtime = ((($refresh_hours*60)+$refresh_minutes)*60)+$refresh_seconds; # Version history # 1.0.0 Original program written # 1.1.0 Changed the output to HTML 4.01 compliant # 2.0.0 Changed the IP addresses to 4 sets of 3 numbers for ease of readability # 2.1.0 Added the ability of checking whois to the IP addresses with a single click # 2.1.1 Added comments and version number for addition to the CPAN archives # 2.1.2 Added better error handling # 2.2.0 changed the local net address selection and added both local net selections. # 3.0.0 Added a new feature to the get log program to allow it to work with logcleaner (strips out the overloads, updated the counter files) # skips 0.0.0.0 IP address. # Also fixed a minor bug in the local IP address filters. # 3.1.0 added a refresh to ensure acurateness of an access log if it's kept on. # 3.2.0 added multiple reverse dns query addresses but it's still secure and hard coded. # 3.3.0 added javascript engine and code to switch between multiple whois servers # 3.4.0 added
\n";
print "",$mytitle,"\n"; print "",$version,"\n"; print "\n"; print " get $version script. \n"; print "line number - IP address - date/time - method - file - protocol - result code - bytes served \n"; print "
You are now using server ",@servers[$whois_server]," \n\n"; print "
\n\n\n"; print "\n"; # Open up the log file open(LOGFILE, $mylogfilename) or $error = 1; if ($error == 1) { print $errormessage; } else { # get the data @data = \n"; }; } else { # convert the numbers into 3 digits each for easier readability # match first number in ip address if ($line =~ m/^\d\D/) { $first = join("","00",substr($line,0,1)); $line =~ s/^\d\D//; } elsif ($line =~ m/^\d\d\D/) { $first = join("","0",substr($line,0,2)); $line =~ s/^\d\d\D//; } else { $first = substr ($line,0,3); $line =~ s/^\d\d\d\D//; }; # match second number in ip address if ($line =~ m/^\d\D/) { $second = join("","00",substr($line,0,1)); $line =~ s/^\d\D//; } elsif ($line =~ m/^\d\d\D/) { $second = join("","0",substr($line,0,2)); $line =~ s/^\d\d\D//; } else { $second = substr ($line,0,3); $line =~ s/^\d\d\d\D//; }; # match third number in ip address if ($line =~ m/^\d\D/) { $third = join("","00",substr($line,0,1)); $line =~ s/^\d\D//; } elsif ($line =~ m/^\d\d\D/) { $third = join("","0",substr($line,0,2)); $line =~ s/^\d\d\D//; } else { $third = substr ($line,0,3); $line =~ s/^\d\d\d\D//; }; # match fourth number in ip address if ($line =~ m/^\d\D/) { $fourth = join("","00",substr($line,0,1)); $line =~ s/^\d\D//; } elsif ($line =~ m/^\d\d\D/) { $fourth = join("","0",substr($line,0,2)); $line =~ s/^\d\d\D//; } else { $fourth = substr ($line,0,3); $line =~ s/^\d\d\d\D//; }; # convert the IP back into 4 sets of 3 digits $ip = join(".", $first, $second, $third, $fourth); $my_ip = join(".", $first, $second, $third, $fourth); &breakip; # The URL of the whois server query if ($whois_server == 0) { $whois = join("", "http://ws.arin.net/cgi-bin/whois.pl?queryinput=", $my_ip); } elsif ($whois_server == 1) { $whois = join("", "http://www.dnsstuff.com/tools/ptr.ch?ip=+", $my_ip, "+"); } elsif ($whois_server == 2) { $whois = join("", "http://www.zoneedit.com/lookup.html?ipaddress=", $my_ip, "&server=&reverse=Look+it+up"); } elsif ($whois_server == 3) { $whois = join("", "http://www.ripe.net/fcgi-bin/whois?form_type=simple&full_query_string=&searchtext=", $my_ip, "&submit.x=9&submit.y=9&submit=Search"); } elsif ($whois_server == 4) { $whois = join("", "http://apnic.net/apnic-bin/whois.pl?searchtext=", $my_ip, "&whois=Go"); } elsif ($whois_server == 5) { $whois = join("", "http://lacnic.net/cgi-bin/lacnic/whois?lg=EN&query=", $my_ip); } elsif ($whois_server == 6) { $whois = join("", "http://www.afrinic.net/cgi-bin/whois?form_type=simple&full_query_string=&searchtext=", $my_ip); } else { $whois = "unable to determine the whois server"; }; $linenumber++; # strip off carriage returns $line =~ s/\n//; # ------ coloring start ------ $line =~ s/games/games<\/b>/g; $line =~ s/stories/stories<\/b>/g; $line =~ s/\ 401\ /\ 401\ <\/b>/; $line =~ s/\ 404\ /\ 404\ <\/b>/; $line =~ s/\ 414\ /\ 414\ <\/b>/; $line =~ s/\ 501\ /\ 501\ <\/b>/; $line =~ s/DR_Scripts/DR_Scripts<\/b>/g; $line =~ s/images/images<\/b>/g; $line =~ s/cgi-bin/cgi-bin<\/b>/g; $line =~ s/css/css<\/b>/g; # ------ coloring end ------ print " ",$linenumber,": ",$ip," ",$line," \n"; }; }; }; close(LOGFILE); if ($linenumber == 0) { print "No log entries at this time. The log has just been freshly cleaned. \n"; }; }; # print the HTML footer print "\n"; print " The End\n\n"; print " | \n