如何在Django中检索远程端口

编程入门 行业动态 更新时间:2024-10-27 17:10:27
本文介绍了如何在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中检索远程端口

本文发布于:2023-06-10 05:43:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/608223.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:端口   如何在   Django

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!