Untitled
unknown
python
a year ago
1.7 kB
48
Indexable
import http.server
import socketserver
import requests
from urllib.parse import urlparse
# Configuration
SOCKS5_PROXY = 'socks5://58653583-zone-custom-region-US:1WpLkXV5wY@f.proxys5.net:6200'
LISTEN_PORT = 8080
class ProxyHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
url = self.path
parsed_url = urlparse(url)
# Forward the request to the SOCKS5 proxy
proxy_response = requests.get(parsed_url.geturl(), proxies={'http': SOCKS5_PROXY, 'https': SOCKS5_PROXY})
# Send the response back to the client
self.send_response(proxy_response.status_code)
self.send_header('Content-type', proxy_response.headers['Content-Type'])
self.end_headers()
self.wfile.write(proxy_response.content)
def do_POST(self):
url = self.path
parsed_url = urlparse(url)
content_length = int(self.headers['Content-Length'])
post_data = self.rfile.read(content_length)
# Forward the request to the SOCKS5 proxy
proxy_response = requests.post(parsed_url.geturl(), data=post_data, headers={'Content-Type': self.headers['Content-Type']}, proxies={'http': SOCKS5_PROXY, 'https': SOCKS5_PROXY})
# Send the response back to the client
self.send_response(proxy_response.status_code)
self.send_header('Content-type', proxy_response.headers['Content-Type'])
self.end_headers()
self.wfile.write(proxy_response.content)
# Set up the HTTP server
handler = ProxyHTTPRequestHandler
httpd = socketserver.TCPServer(("", LISTEN_PORT), handler)
print(f"Serving on port {LISTEN_PORT}")
httpd.serve_forever()
Editor is loading...
Leave a Comment