5 Cent tip for today [ TCP Port Forwarder ]

Started by newdep, February 28, 2004, 07:09:48 AM

Previous topic - Next topic

newdep

;;

;; Quick and Dirty Portforwarder TCP exmaple, no real error checking done.

;; connects one tcp port to the other, closed the listener port when client is

;; connected

;;

;; run the portforwarder, then connect with i.e. ssh localhost -p 2200

;; and you will be forwarded internal towards the 22 sshd port.

;;

;; Its pritty easy to include PortSniffing in this PortForwarder, just display

;; the cbuff and rbuff content, printable character, during io.

;;

;; This portforwarder does not run smoothly for http pages because

;; of the line-based protocol http.



;; setup a listener

(unless (set 'server (net-listen 2200 ))

        (begin

        (println (net-error))

        (exit))



        (println "Server started") )



;; setup a client session to localhost sshd port 22

(unless (set 'remote (net-connect "localhost" 22))

        (begin

        (println (net-error))

        (exit))

       

        (println "Remote opened") )



;; wait for connection and close the listener

(if (set 'client (net-accept server))

        (begin

        (net-close server)

        (println "Client Connected" (net-peer client))) )



;; repeat until an error occeurs

(until (net-error)



        (if (net-select client "read" 1000)

                ;; read data from client

                (begin

                        ( net-receive client 'cbuff (set 'csize (net-peek client)) )

                        ( net-send remote 'cbuff csize )))



        (if (net-select remote "read" 1000)

                ;; read data from remote

                (begin

                        (net-receive remote 'rbuff (set 'isize (net-peek remote)) )

                        (net-send client 'rbuff isize)))

)



(println "Server Shutdown or " (net-error))

(exit)





Norman.
-- (define? (Cornflakes))

newdep

#1
Addon, with some accesslisting on the portscanner with predefined ip addresses the portforwarder will have some basic security for access.



Still very easy to port my programs towards newlisp,

the portforwarder was done in a few minutes, which indirectly implies

that newlisp is quicky to learn and easy to use ;-) like it..!



Norman.
-- (define? (Cornflakes))

Lutz

#2
Great thingy this port forwarder! thanks for showing how to put the net-functions to work this way.



Lutz