Created
September 21, 2010 14:26
-
-
Save Motoma/589753 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
import select | |
import socket | |
import time | |
TIME_WAIT = 0.01 | |
BIND_ADDR = '' | |
BIND_PORT = 8443 | |
SERV_ADDR = 'server.example.com' | |
SERV_PORT = 8443 | |
def Route(): | |
listener = socket.socket() | |
listener.bind((BIND_ADDR, BIND_PORT)) | |
listener.listen(1) | |
client, caddr = listener.accept() | |
listener.close() | |
server = sock.socket() | |
server.connect((SERV_ADDR, SERV_PORT)) | |
running = True | |
while running: | |
try: | |
rlist = select.select([client, server], [], [])[0] | |
if client in rlist: | |
buf = client.recv(4096) | |
if len(buf) == 0: | |
running = False | |
# Parse, modify, or halt traffic here | |
server.send(buf) | |
if server in rlist and running: | |
buf = server.recv(4096) | |
if len(buf) == 0: | |
running = False | |
# Parse, modify, or halt traffic here | |
client.send(buf) | |
except: | |
pass | |
try: | |
client.close() | |
except: | |
pass | |
try: | |
server.close() | |
except: | |
pass | |
if __name__ == '__main__': | |
Route() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment