又一次被linux的工具震惊了

来源:互联网 发布:amarra mac 编辑:程序博客网 时间:2024/05/16 19:11

    前一篇博客还写了自己写的端口转发工具,今天偶然在网上看到讲命名管道和netcat配合的用法,被彻底雷倒了。
    原来以为netcat做不到,原来是自己想不到,而不是netcat做不到……
    方法如下:
    $ mknod backpipe p
    建立一个命名管道.

    listener-to-client 转发:
    $ nc -l -p [localport] 0< backpipe |
        nc [target ip] [port] |
        tee backpipe
    漂亮吧?
    继续:
    listener-to-listener 转发:
    $ nc -l -p [localport] 0< backpipe |
        nc -l -p [localport2] |
        tee backpipe
   
    client-to-client 转发:
    $ nc [ip1] [port1] 0< backpipe |
        nc [ip2] [port2] |
        tee backpipe


   还有更雷的方法,用自身的 -e 参数:

    $ echo nc [ip] [port] > relay.sh

    $ chmod +x relay.sh

    $ nc -l -p [port2] -e relay.sh

 

    我晕菜了,原来那个程序是白写了。
    强大的linux, 强大的netcat !