案例: 有一个应用程序需要把数据输出给远程tcp端口44441, 为了安全, 数据会再次转发到端口44442,从而使得连接到端口44442的应用可以实时接收到数据。
为此,在远程tcp主机编写了shell脚本如下:
#!/bin/bash -l
pipe=/tmp/testpipe
ps -ef | grep -e '44441' -e '44442' | grep -v 'grep' | awk '{print $2;}' | xargs kill -9 > /dev/null 2>&1
trap "rm -f $pipe" EXIT
if [[ ! -p $pipe ]]; then
mkfifo $pipe
fi
ncat -lk -p 44441 0<"$pipe" | ncat -lk -p 44442 | tee $pipe &
本文介绍了一种通过Shell脚本实现的数据转发方案。该方案使用ncat工具将从TCP端口44441接收的数据转发到44442端口,同时通过管道实现数据的实时传递。

被折叠的 条评论
为什么被折叠?



