ADDED:
当客户端发送HTTP请求时,作为机器的一个源TCP端口,将在NAT进程中进行修改。最后,SYN(TCP)到Web服务器将来自,例如端口P1。我需要Web服务器从其接收连接请求的端口P1。
现在在HttpRequest的meta dict中,我无法看到它。有没有其他的方法?
解决方案目的地(服务器)端口包含在请求的元词典。
def get_port(request):如果请求中为'SERVER_PORT'.META: return request.META ['SERVER_PORT'] else : return无源端口在TCP的应用层不可访问/ IP堆栈。
I am writing a web server script and need remote port from which a client connected. Is there any way I may retrieve it? I am using django framework for development.
ADDED:
When a client sends a HTTP Request, there would be one source TCP port at the machine, which would be modified in NAT process. Finally, SYN (TCP) to web server would be from, say port P1. I need that port P1 from which the web server receives a connection request.
Now in HttpRequest meta dict, I was not able to see it. Is there any other way?
解决方案The destination (server) port is included in the request's meta dictionary.
def get_port(request): if 'SERVER_PORT' in request.META: return request.META['SERVER_PORT'] else: return NoneThe source port will not be accessible at the application layer of the TCP/IP stack.
更多推荐
如何在Django中检索远程端口
发布评论