首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >永远使用netcat代理

永远使用netcat代理
EN

Server Fault用户
提问于 2012-12-12 14:02:29
回答 1查看 26.9K关注 0票数 17

我正在使用netcat代理一个VNC TCP服务器端口。代理机器运行linux。

这是我使用的comand:

代码语言:javascript
复制
mkfifo backpipe
nc -l 5902  0<backpipe | nc 10.1.1.116 5902 1>backpipe

10.1.1.116是在端口5902上运行原始VNC服务的“远程”机器。在此命令之后,其他机器的本地主机上就可以使用VNC服务。

但是在每个VNC会话之后,netcat“代理服务器”就停止了,这就是netcat的工作方式。

如何使netcat在VNC会话终止后保持“代理服务”运行?

作为一种解决办法,我将netcat命令行放在一个无限循环中:

代码语言:javascript
复制
mkfifo backpipe
while true; do   nc -l 5902  0<backpipe | nc 10.1.1.116 5902 1>backpipe; done

但是我更喜欢一种“官方”的netcat解决方案,它根本不中断服务。

我读过关于"-“参数的文章,但我不确定这是否符合情况,而且我还不能正确地应用它。

补充意见:

当然,我可以以不同的方式使用ssh隧道来实现这一点,但是我想要一个没有加密开销的解决方案,以使它对VNC客户端尽可能响应。否则,不同的代理解决方案就可以了。

客户端必须是VNC,其他协议是不可能的。

EN

回答 1

Server Fault用户

回答已采纳

发布于 2012-12-12 14:05:31

-k选项应该可以做到这一点。

来自nc(1)的手册:

代码语言:javascript
复制
 -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转发程序示例,当然需要一些修改。

代码语言:javascript
复制
   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.
票数 25
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/457433

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档