#!C:\PROGRA~1\PERL\BIN\PERL.EXE -w -t
# or #!/usr/local/bin/perl -w -t
use Socket;
use Strict;

print "Content-Type: text/html; charset=iso-8859-1\n";
print "Pragma: no-cache\n\n";
# Please note that one plank line separates HTTP header
#                       form the contents of a Web page


print <<enough;
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1">
<title>Output of a sample CGI Script</title>
<meta name="robots" content="noindex,nofollow">
</head>
<body style="background: #CCFFFF;">
enough

### insert your code below this line



my $ipad = $ENV{'REMOTE_ADDR'};
my $name = ip2name($ipad);
my $syst = $ENV{'HTTP_USER_AGENT'};

print "<p>This script was run on request that came from a computer with the IP address of <code>$ipad</code>.</p>\n";
print "<p>I looked it up and found out that it actually is <code>$name</code>.\n</p>";
print "<p>I also know that your computer is running <code>$syst</code>.\n</p>";



### end of customization - now close the HTML page

print <<enough;
</body>
</html>
enough

exit(0);



###########
sub ip2name
{
    my $ad=$_[0] or return("undefined");
    return (gethostbyaddr(pack('C4', split(/\./, $ad)), AF_INET) or $ad);
}