#!/usr/bin/python ''' redir.py 0.1 (c) 2003 Jan ONDREJ (SAL) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. ''' import sys,os,socket,traceback BLOCK_SIZE=1024*80 LPORT=7890 LHOST="0.0.0.0" RPORT=7890 RHOST=sys.argv[1] s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1) try: s.bind((LHOST,LPORT)) s.listen(2) except socket.gaierror,(ec,es): print "BIND ERROR:",es sys.exit(2) try: while 1: conn,addr = s.accept() print "Accept:",addr try: cli=socket.socket(socket.AF_INET,socket.SOCK_STREAM) cli.connect((RHOST,RPORT)) except socket.error,(ec,es): print "Connectr error:",es sys.exit(3) buf=conn.recv(10000000) cli.send(buf) while 1: buf=cli.recv(BLOCK_SIZE*10) if buf: conn.send(buf) else: break cli.shutdown(2) cli.close() conn.shutdown(2) conn.close() except KeyboardInterrupt: print "\nInterrupted!" sys.exit(0)