下面的python代码用于监控本机的8080端口,当用于通过http请求,服务器返回固定的html代码
代码语言:javascript复制import SocketServer
class MyRequestHandler(SocketServer.BaseRequestHandler):
def handle(self):
print "From:", self.client_address
input = self.request.recv(10240)
print input.replace('r', '')
self.request.send("HTTP/1.1 200 OKrn")
self.request.send("Content-Type: text/htmlnn")
self.request.send("<HTML><BODY><H2>Hello!</H2></BODY></HTML>")
self.request.close()
myServer = SocketServer.TCPServer(('', 8080),MyRequestHandler)
myServer.handle_request()
</pre>