如何在具有公共 IP 但都在 LAN 后面的两台机器之间进行通信(python 解决方案)? [英] How to communicate between two machines with public IP but both behind LAN(python solution)?

查看:53
本文介绍了如何在具有公共 IP 但都在 LAN 后面的两台机器之间进行通信(python 解决方案)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为此寻找一个简单的python解决方案:

Looking for a simple python solution for this:

假设机器A的本地IP是192.168.1.5,公网IP是111.11.111.11,机器B的本地IP是10.0.0.5,公网IP是222.22.222.22,现在我需要在这两台机器之间通信,你怎么做那个?

Assume Machine A's local IP is 192.168.1.5 and public IP is 111.11.111.11, Machine B's local IP is 10.0.0.5 and public IP is 222.22.222.22, now I need to communicate between these two machines, how do you do that?

我在同一网络上看到了许多服务器和客户端的套接字编程示例,但是如何在不更改路由器配置(端口转发等)的情况下连接不同网络后面的机器?

I've seen lots of socket programming examples with both server and client on the same network, but how do you connect machines behind different networks without changing router configurations(port forwarding etc.)?

如果机器 A 在 LAN 后面怎么办:本地 IP 192.168.1.5,公共 IP 111.11.111.11;机器B是一个公网IP为222.22.222.22的HTTP服务器;现在您可以轻松地通过 HTTP 请求从 A 到达 B,但是从机器 B 到达机器 A 的最佳解决方案是什么?

What if Machine A's behind LAN: local IP 192.168.1.5, public IP 111.11.111.11; Machine B's an HTTP server with a public IP of 222.22.222.22; now you can easily reach B from A through HTTP requests, but what's the best solution to reach machine A from machine B?

推荐答案

打孔是实现这一目标的一种方法.打孔是一种 NAT 穿越技术,它允许 NAT 后面的设备之间直接通信.并非所有 NAT 都支持打孔.但是很大比例的 NAT 允许.

Hole Punching is one way to achieve this. Hole punching is a NAT traversal technique, which allows direct communication between devices behind NATs. Not all NATs support hole punching. But a good percentage of NATs allow.

http://www.brynosaurus.com/pub/net/p2pnat/

这个链接有详细的解释.他们也给出了统计数据.

This link explains it in detail. They have given the statistics also.

这篇关于如何在具有公共 IP 但都在 LAN 后面的两台机器之间进行通信(python 解决方案)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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