T
T
tostpypy2016-04-13 11:25:22
Python
tostpypy, 2016-04-13 11:25:22

How to pass real ip of connected client to python proxy?

Good day. I'm new to python, I recently got to sockets, it became necessary to write a proxy application that would proxy any traffic.
So, there is a proxy application that listens on a specific port, it must transmit information (traffic) to a given target, to its IP and port.

A small piece of server code:

HOST, PORT = "", 9091

server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler)
SocketServer.ThreadingTCPServer.allow_reuse_address = True
ip, port = server.server_address
server_thread = threading.Thread(target=server.serve_forever)
server_thread.daemon = True
server_thread.start()

Here comes the forwarding:
class Forwarder(threading.Thread):
def __init__(self, source):
threading.Thread.__init__(self)
self.source = source
self.dest = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.dest.connect (("target ip", 20000))

Everything works, but, of course, data containing the ip of the proxy application server, and not real clients, reaches the source.

The question is where to dig, what to use to transfer the IP of clients connected to the proxy.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2016-04-13
@fox_12

Search for adding and processing x-forwarded-for header

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question