#!/usr/bin/newlisp # # Program to forward TCP ports # Based upon my Scriptbasic demo program # # Tested with newLisp 8.3.1 # # Nov 3, 2004 - PvE # #------------------------------------ # Set some constants (constant 'remoteaddress "shell.xxx.nl") (constant 'remoteport 22) (constant 'localport 55000) (constant 'fw-timeout 1000) # Get listenport (set 'localsocket (net-listen localport)) (unless localsocket (begin (println "Listening to port " (string localport) "failed.\n") (exit))) # Waiting for incoming connection - endlessly (while true (begin (println "Waiting for connection on port " (string localport) "...") (set 'localconnect (net-accept localsocket)) # Connection request received (if localconnect (begin (println "Incoming connection from " (first (net-peer localconnect))) # Connect to the remotehost first (set 'remoteconnect (net-connect remoteaddress remoteport)) (if (= remoteconnect nil) (begin (println "Cannot connect to remote host!") (exit))) # Only 1 connection at a time possible (while (= (length (net-sessions)) 3) # Now read incoming traffic and forward to remote host (if (net-select localconnect "r" fw-timeout) (begin (net-receive localconnect 'buffer 1024) (net-send remoteconnect 'buffer))) # Read incoming traffic and forward to localhost (if (net-select remoteconnect "r" fw-timeout) (begin (net-receive remoteconnect 'buffer 1024) (net-send localconnect 'buffer)))) # Close local port and remote port (net-close localconnect) (net-close remoteconnect) ) (print "Could not connect\n"))))