[英]How to get IP address of the client who made request to python SimpleHTTPServer?
I am setting python local server using python -m SimpleHTTPServer
, I made that server publicly available using ngrock
and have some public IP address like http://2ee94---.ngrok.io
.我正在使用python -m SimpleHTTPServer
设置 python 本地服务器,我使用ngrock
使该服务器公开可用,并有一些公共 IP 地址,如http://2ee94---.ngrok.io
。 Now I am making the request
to the public IP address.现在我正在向公共 IP 地址发出request
。 I want to get IP address from request.我想从请求中获取 IP 地址。 But I am getting the only status in the terminal.但是我在终端中获得了唯一的状态。 How to get details (IP address of client) of the request.如何获取请求的详细信息(客户端的 IP 地址)。
HTTP Requests
-------------
GET / 200 OK
GET / 200 OK
I got it done after setting up my own handler class,我在设置我自己的处理程序类后完成了它,
import SimpleHTTPServer
import SocketServer
class MyHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def handle_one_request(self):
print(self.client_address[0])
return SimpleHTTPServer.SimpleHTTPRequestHandler.handle_one_request(self)
httpd = SocketServer.TCPServer(("", 8080), MyHandler)
while True:
httpd.handle_request()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.