Skip to content

Instantly share code, notes, and snippets.

@Motoma
Created September 21, 2010 14:26
Show Gist options
  • Save Motoma/589753 to your computer and use it in GitHub Desktop.
Save Motoma/589753 to your computer and use it in GitHub Desktop.
#! /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