Skip to content

Instantly share code, notes, and snippets.

@eeddaann
Created February 13, 2014 20:33
Show Gist options
  • Save eeddaann/8983259 to your computer and use it in GitHub Desktop.
Save eeddaann/8983259 to your computer and use it in GitHub Desktop.
import socket
import threading
#this program sits in the middle between a client and a server
# it should listen to data from the client
#detect dos
#and send it to server
# todo!
#TODO: prevent from server to crash
#TODO: let server detect diffrent clients
host="localhost"
out_port = 35000 #port of server
in_port = 33440 #port of client
size = 1024
def listen():
in_socket.listen(5)
in_socket= socket.socket(socket.AF_INET, socket.SOCK_STREAM) #this socket only recive data from client
out_socket=socket.socket(socket.AF_INET, socket.SOCK_STREAM) #this socket only send data to server
in_socket.bind((host,in_port))#wait for client
threading.Thread(target=listen()).start()# don't worry, it just let the in_socket to listen the client and don't disturb the sending to the server
out_socket.connect((host,out_port))
while 1:
client, address = in_socket.accept()
data = client.recv(size)
if data:
print 'Got connection from', address
#here our super_duper_double_cool function will block suspicious clients
out_socket.send(data)
print("sent")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment