I am trying to follow this example and translating it to python3 in order to create a proxy server to be able to access some http webpages through it.
I'm running my script in an AWS EC2 where I have opened port 80.
I run the code below, go to firefox and type X.X.X.X/www.aena.es (Xs are the public ip of my EC2 and aena is a spanish http webpage).
I can get my browser to show the html code of the web page I am asking for. But not the web page itself. Is there an easy way to do this?
os.system('sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination ' + local_ip + ':8888')
os.system('sudo iptables -A FORWARD -p tcp --dport 80 -j ACCEPT')
PORT = 8888
class Proxy(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
full_path = 'http:/' + self.path
print(full_path)
req = urllib.request.urlopen(full_path)
self.copyfile(req, self.wfile)
httpd = socketserver.ForkingTCPServer((local_ip, PORT), Proxy)
print("serving at port ", PORT)
httpd.serve_forever()