Transparent HTTP proxy in python « ejohansson.se
Transparent HTTP proxy in python
I recently wanted to modify a web resource that a device on my local network loads when starting. To avoid having a static local modified copy of the resource I wrote a simple transparent HTTP proxy in python using the Twisted networking engine (which btw was a joy to use) which does the modification when the resource is loaded. The code is not modular (e.g. the resource modification is hard coded in the processResponse() function) and the logging is very verbose, but if anyone is interested the code is available on github: transparent-proxy.git.
The proxy is now running on my local server which sits behind the real gateway. Besides making the device use the server as gateway and enable NAT on the server this single iptables rule is all that is needed:
iptables -t nat -A PREROUTING -s $CLIENT_IP -p tcp --dport 80 -j REDIRECT --to-port 8080