Skip to content

变量说明

  • src_host: 源主机地址
  • src_port: 源端口
  • local_port: 本地端口
    • local_host: 本地地址

nc

语法

案例

socat

语法

shell
socat TCP4-LISTEN:${local_port},bind=${local_host},reuseaddr,fork TCP4:${src_host}:${src_port}
  • reuseaddr表示可以重复使用本地端口
  • fork表示创建新的进程来处理连接

案例

shell
socat TCP4-LISTEN:15672,bind=192.168.1.252,reuseaddr,fork TCP4:192.168.1.247:15672

ncat

语法

shell
ncat --sh-exec "ncat ${src_host} ${src_port}" -l ${local_port}  --keep-open

案例

例如需要将当前局域网的192.168.172.131主机的80端口转发到本地的9876端口

shell
ncat --sh-exec "ncat 192.168.172.131 80" -l 9876  --keep-open

Last updated: