Python P2P网络(NAT Punchtrough)

2024-10-01 15:36:14 发布

您现在位置:Python中文网/ 问答频道 /正文

为了便于理解,我们假设这两台机器都在ipv4上,在NAT网络后面。我希望能打开两台机器上的一个插座,让机器通过这些插座(或类似的系统)连接。我知道这需要nat punchthrough,但我不确定nat punchtrough如何应用(曾经连接的套接字现在可以接受吗?)任何在python中使用过nat punchthrough的人我都会非常感谢你的帮助。在


Tags: 网络机器系统nat插座ipv4punchthroughpunchtrough
3条回答

这称为“NAT遍历问题”
有三种解决方案

  1. 静态配置NAT以将给定端口的传入连接请求转发到服务器。它也称为端口转发
    enter image description here

  2. 互联网网关设备(IGD)协议。允许nate主机:
    -了解NAT路由器的公共IP地址
    -添加/删除端口映射(带租约时间)
    i、 自动化静态NAT端口映射配置
    enter image description here

  3. 中继(用于Skype)
    -nate客户端与中继/服务器建立连接
    -外部中继连接到客户端
    -中继连接到连接之间的数据包
    enter image description here

有关更多信息,请参阅《计算机网络自上而下方法》(Computer Networking A Top-Down Approach)第6版James F.Kurose,Keith W.Ross第4章>网络地址翻译(NAT)

打孔在the Wikipedia entry中有很好的描述

Hole punching is a computer networking technique for establishing communications between two parties in separate organizations who are both behind restrictive firewalls. Used for applications such as online gaming, P2P and VoIP, both clients establish a connection with an unrestricted third-party server that uncovers external and internal address information for them. Since each client initiated the request to the server, the server knows their IP addresses and port numbers assigned for that session, which it shares one to the other. Having valid port numbers causes the firewalls to accept the incoming packets from each side. ICMP hole punching, UDP hole punching and TCP hole punching respectively use Internet Control Message, User Datagram and Transmission Control Protocols. Using TCP nefarious hole punching, it is possible to send compressed SYN packets through into a common ACK path.

这里有TCP,UDP和ICMP保持穿孔的各种技术的链接。在

一般来说,要从a到B打孔(都在NAT之后),需要一个第三方服务器C,它们都可以首先连接到该服务器。服务器将A的连接信息发送到B,反之亦然。A&B然后使用此信息尝试彼此直接连接,但该过程并非100%可靠。在

如果你没有第三方服务器,那么我认为它不会工作。在

编辑

您可能还想看看UPnPhttp://en.wikipedia.org/wiki/Universal_Plug_and_Play#NAT_traversal。我不确定路由器对它的支持有多好,但它听起来适合您的应用程序。在

听起来你需要设置端口转发,实际上就是告诉你的路由器将它在一个特定端口上接收到的呼叫转发到它后面的服务。在

这通常是通过路由器的管理界面来完成的。在

相关问题 更多 >

    热门问题