Skip to content

Instantly share code, notes, and snippets.

@owyongsk
Created Nov 21, 2019
Embed
What would you like to do?
Prank Redirect
import SimpleHTTPServer
import SocketServer
import random
from urlparse import urlparse, parse_qs
class Redirect(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
term = parse_qs(urlparse(self.path).query)['q'][0]
self.send_response(302)
if random.randint(1, 101) > 95:
self.send_header('Location', 'https://www.youtube.com/watch?v=dQw4w9WgXcQ')
# self.send_header('Location', 'https://www.pornhub.com/search?search=%s' % (term))
else:
self.send_header('Location', 'https://google.com/search?q=%s' % (term))
self.end_headers()
SocketServer.TCPServer(("", 8080), Redirect).serve_forever()
# nohup python redirect.py &
# http://localhost:8080/q?q=%s
@dominicwong617

This comment has been minimized.

Copy link

@dominicwong617 dominicwong617 commented Nov 21, 2019

I think it should be lower than 95, more like 50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment