How to communicate between two computers with a public IP but also behind a LAN (python solution)?

Looking for a simple python solution for this:

Suppose the local IP is 192.168.1.5 and the public IP is 111.11.111.11, the local IP of Machine B is 10.0.0.5 and the public IP is 222.22.222.22, now I need to communicate between these two cars, how do you do that?

I have seen many examples of socket programming with both server and client on the same network, but how do you connect computers on different networks without changing the router configuration (port forwarding, etc.)?

EDIT:

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

+3


source to share


2 answers


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

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



This link explains it in detail. They also provided statistics.

+2


source


In the first case, when both devices are behind NAT, you either need to punch holes or use the python UPnP library for port forwarding if you don't want to manually forward them.



In the second case, the program on machine A must initialize the connection. NAT will create a translation entry in this table for this purpose. Basically, all packets sent from machine B on the public IP address of your network will now be redirected to the computer as a local IP address.

0


source







All Articles