5

Im using the following code to proxy my traffic within my Django application through a socks proxy,

def bind_proxy_port(enable=True):
    try:
        if enable == True:
            socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 8080)
            socket.socket = socks.socksocket
        return True
    except:
        raise Exception("unable to set proxy 127.0.0.1:8080")

The traffic im sending through this is HTTPS traffic. However this results in traffic to Rabbit-MQ to also be proxied which breaks the application. Is there a way to define only a single destination port to be proxied through and/or any other solution ?

felix001
  • 15,341
  • 32
  • 94
  • 121
  • How do you use this portion of code? Run as a separate app on specific port? Looks like other apps also connects to the same ports. – Eugene Lisitsky Mar 16 '16 at 11:18

1 Answers1

0

Assuming that you're using one of the SocksiPy forks. Lets consider this version: https://github.com/Anorov/PySocks

You could try to inherit from socks.socksocket (https://github.com/Anorov/PySocks/blob/1.5.0/socks.py#L164) and override its connect method https://github.com/Anorov/PySocks/blob/1.5.0/socks.py#L450 and may be some others, depending on what you need in your app.

In your custom class you could add additional logic which would only proxy for the specified set of ports and resort to the unchanged socket version otherwise (see these lines https://github.com/Anorov/PySocks/blob/1.5.0/socks.py#L469)

Oleg Kuralenko
  • 11,003
  • 1
  • 30
  • 40