19 lines of code for a proxy server (that works amazingly too!)
It works for HTTP, and HTTPS!
Maybe it works for a few other things?
made by yours truly!
import socket
import urllib2
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('',8080))
s.listen(1000)
def HandleProxy(c):
Request=c.recv(1024)
Parse=Request.split()
try:
req = urllib2.Request(Parse[1])
html=urllib2.urlopen(req).read()
except (urllib2.URLError,urllib2.HTTPError) as e:
html="<b>Proxy error: "+e.reason[1]+"</b>"
c.send(html)
print "Requested data:\n"+ Request
while 1:
(c,addr)=s.accept()
print addr[0]+":"+str(addr[1])+" connected!"
HandleProxy(c)
For those of you who want a multi-threaded version here you go (not 19 lines lol):
#Simple python base proxy server
#coded by fl0urite!
from threading import Thread
import socket
import urllib2
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('',8080))
s.listen(1000)
def HandleProxy(c):
Request=c.recv(1024)
Parse=Request.split()
try:
req = urllib2.Request(Parse[1])
html=urllib2.urlopen(req).read()
except (urllib2.URLError,urllib2.HTTPError) as e:
html="<b>Proxy error: "+e.reason[1]+"</b>"
c.send(html)
print "Requested data:\n"+ Request
while 1:
(c,addr)=s.accept()
print addr[0]+":"+str(addr[1])+" connected!"
thread = Thread(target=HandleProxy(c))
thread.start()
Have fun!
Staff note: edit button. Do you use it?
Fl0urite's reply: On this forum it is the modify button, so no.