Are there simple port forwarding descriptions using python?

I can just plug in the socket on the same computer using

server:

import socket s = socket.socket() host = socket.socket() port = 8000 s.bind((host,port)) s.listen(5) while true: c,addr = s.accept() print 'got connection from', addr c.send('thank you for connecting') c.close() 

client:

 import socket s = socket.socket() host=socket.gethostname() port = 8000 s.connect((host,port)) print s.recv(1024) 

What changes should be made if it is connected between my laptop and the private server I'm working on? I realized from my searches that portforwarding is the best way to do this, but have not found any explanation or guidance on how to do this.

Thank you

+6
source share
2 answers

If you need a Python port forwarding implementation, there is an old but excellent ActriveState recipe that implements an asynchronous port forwarding server using only the standard Python library (socket, asyncore). You can poke at code.activestate.com .

PS There is also a link to the streaming version of the script.

+1
source

If you really don't need to do this in python, just use netcat: -

http://netcat.sourceforge.net/

Port Forwarding or Port Mapping In Linux, NetCat can be used for port forwarding. The following are nine ways to port forwarding to NetCat (-c switch is not supported, however - they work with the implementation of ncat netcat):

 nc -l -p port1 -c ' nc -l -p port2' nc -l -p port1 -c ' nc host2 port2' nc -l -p port1 -c ' nc -u -l -p port2' nc -l -p port1 -c ' nc -u host2 port2' nc host1 port1 -c ' nc host2 port2' nc host1 port1 -c ' nc -u -l -p port2' nc host1 port1 -c ' nc -u host2 port2' nc -u -l -p port1 -c ' nc -u -l -p port2' nc -u -l -p port1 -c ' nc -u host2 port2' 

Source: - http://en.wikipedia.org/wiki/Netcat#Port_Forwarding_or_Port_Mapping

It is usually used in most * nix distributions, and there is also a Win32 port: -

http://www.stuartaxon.com/2008/05/22/netcat-in-windows/

+2
source

Source: https://habr.com/ru/post/919795/


All Articles