Browse Source

Added hello_host.cgi, a trivial HTTP echoer

Alois Mahdal 11 years ago
parent
commit
167211804c
1 changed files with 29 additions and 0 deletions
  1. 29
    0
      cgi-bin/hello_host.cgi

+ 29
- 0
cgi-bin/hello_host.cgi View File

@@ -0,0 +1,29 @@
1
+#!/usr/bin/perl -w
2
+
3
+use Sys::Hostname;
4
+
5
+sub mygetstrtime {
6
+	my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime (time);
7
+	$year += 1900; $mon += 1;
8
+	return sprintf "%02d/%02d/%04d %02d:%02d:%02d", $mon, $mday, $year, $hour, $min, $sec;
9
+}
10
+
11
+print "Content-type: text/plain; charset=utf-8\n";
12
+print "Pragma: no-cache\n";
13
+print "Cache-Control: no-cache\n\n";
14
+
15
+my $ip = $ENV{'REMOTE_ADDR'};
16
+my $port = $ENV{'REMOTE_PORT'};
17
+my $myip = $ENV{'SERVER_ADDR'};
18
+my $myport = $ENV{'SERVER_PORT'};
19
+my $myhostname = hostname;
20
+my $mylocaltime = &mygetstrtime;
21
+
22
+print "Client:\n";
23
+print "  $ip:$port\n";
24
+print "\n";
25
+print "Server:\n";
26
+print "  $myip:$myport\n";
27
+print "  $myhostname:$myport\n";
28
+print "  $mylocaltime\n";
29
+