Last active
December 18, 2015 22:08
-
-
Save bhenderson/5851951 to your computer and use it in GitHub Desktop.
NetCat (nc) pipe. Using coproc available in bash 4.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
server=$1 | |
port=$2 | |
lport=${3:=$port} | |
# stdout will be server | |
# stderr will be client | |
exec 3>&1 | |
# use coproc instead of named pipe. | |
# bash 4 | |
coproc { nc $server $port | tee >( cat >&3 ) ;} | |
{ nc -lk -p $lport | tee >( cat >&2 ) ;} <&${COPROC[0]} >&${COPROC[1]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment