5 Cent tip for today [ TCP Port Forwarder ]

Featuring the Dragonfly web framework
Locked
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

5 Cent tip for today [ TCP Port Forwarder ]

Post by 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.

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

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.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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

Lutz

Locked