import socket, os, WConio, thread password = "taviMmEA" s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(('', 23 )) s.listen(1) #see if twisted speeds it up #try twisted's process class #make a line input function # def send(conn, x): conn.send(x.replace('\xff','\xff\xff').replace('\n','\r\n')) def recv(): try: x = conn.recv(1024).replace('\xff\xff','') y = x.find('\xff') if y>-1: x = x[:y]+x[y+3:] return x except socket.timeout: return '' class connection: def __init__(conn): self.conn = conn self.stop = False def listen(): while not self.stop: try: output = out.read(1) WConio.cputs(output) send(self.conn, output) except: break self.conn.close() while 1: try: conn, addr = s.accept() except: continue conn.settimeout(.001) print "connected:",addr # conn.send("\x1b[m\xff\xfe\x01") #disable echo conn.send("\x1b[m") send(conn, "Enter password: ") st=" " while st[-1]!="\n": try: st+=recv() except socket.timeout: pass print "password:",repr(st[1:-2]) if st[1:-2]!=password: conn.close() continue send(conn, "Enter command: ") st=" " while st[-1]!="\n": try: st+=recv() except socket.timeout: pass print "command:",st[1:-1] n, out = os.popen4(st[1:]) a = new connection(conn) while 1: try: try: x = recv() if x: n.write(x) except socket.timeout: pass except: a.stop = True break conn.close()