我正在使用netcat代理一个VNC TCP服务器端口。代理机器运行linux。
这是我使用的comand:
mkfifo backpipe
nc -l 5902 0<backpipe | nc 10.1.1.116 5902 1>backpipe10.1.1.116是在端口5902上运行原始VNC服务的“远程”机器。在此命令之后,其他机器的本地主机上就可以使用VNC服务。
但是在每个VNC会话之后,netcat“代理服务器”就停止了,这就是netcat的工作方式。
作为一种解决办法,我将netcat命令行放在一个无限循环中:
mkfifo backpipe
while true; do nc -l 5902 0<backpipe | nc 10.1.1.116 5902 1>backpipe; done但是我更喜欢一种“官方”的netcat解决方案,它根本不中断服务。
我读过关于"-“参数的文章,但我不确定这是否符合情况,而且我还不能正确地应用它。
补充意见:
当然,我可以以不同的方式使用ssh隧道来实现这一点,但是我想要一个没有加密开销的解决方案,以使它对VNC客户端尽可能响应。否则,不同的代理解决方案就可以了。
客户端必须是VNC,其他协议是不可能的。
发布于 2012-12-12 14:05:31
-k选项应该可以做到这一点。
来自nc(1)的手册:
-k Forces nc to stay listening for another connection after its
current connection is completed. It is an error to use this
option without the -l option.我注意到Debian/Ubuntu上的netcat-traditional包并没有像它应该的那样一直在监听。在这种情况下,使用netcat-openbsd包代替,然后再试一次!
或者,使用socat,它更适合您对代理服务器的使用。一个来自socat手册的随机TCP转发程序示例,当然需要一些修改。
socat -d -d -lmlocal2 \
TCP4-LISTEN:80,bind=myaddr1,reuseaddr,fork,su=nobody,range=10.0.0.0/8 \
TCP4:www.domain.org:80,bind=myaddr2
TCP port forwarder, each side bound to another local IP
address (bind). This example handles an almost arbitrary
number of parallel or consecutive connections by fork'ing a
new process after each accept() . It provides a little secu‐
rity by su'ing to user nobody after forking; it only permits
connections from the private 10 network (range); due to
reuseaddr, it allows immediate restart after master
process's termination, even if some child sockets are not
completely shut down. With -lmlocal2, socat logs to stderr
until successfully reaching the accept loop. Further logging
is directed to syslog with facility local2.https://serverfault.com/questions/457433
复制相似问题