import sys import time import BaseHTTPServer HOST_NAME = 'localhost' PORT_NUMBER = 50080 class TestHandler(BaseHTTPServer.BaseHTTPRequestHandler): def do_HEAD(s): s.send_response(200) s.send_header("Content-type", "text/html") s.end_headers() def do_GET(s): """Respond to a GET request.""" s.send_response(200) s.send_header("Content-type", "text/html") s.end_headers() s.wfile.write("%s %s" %(HOST_NAME,PORT_NUMBER)) s.wfile.write("

%s %s

" %(HOST_NAME,PORT_NUMBER)) s.wfile.write("

You accessed path: %s

" % s.path) s.wfile.write("") if __name__ == '__main__': if sys.argv[1:]: PORT_NUMBER = int(sys.argv[1]) server_class = BaseHTTPServer.HTTPServer httpd = server_class((HOST_NAME, PORT_NUMBER), TestHandler) print time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, PORT_NUMBER) try: httpd.serve_forever() except KeyboardInterrupt: pass httpd.server_close() print time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, PORT_NUMBER)