如何在Django中检索远程端口 [英] How to retrieve remote port in Django

查看:171
本文介绍了如何在Django中检索远程端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Web服务器脚本,需要一个客户端连接的远程端口。有什么办法可以检索吗?我正在使用django框架进行开发。



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 None

The source port will not be accessible at the application layer of the TCP/IP stack.

这篇关于如何在Django中检索远程端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆