-
-
Save VictorNS69/5e2c8236d5be3ed4bcac3c4637088607 to your computer and use it in GitHub Desktop.
easy tcp port forwarding by netcat
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
#!/usr/bin/env bash | |
set -e | |
if [ $# != 3 ]; then | |
echo 'Usage: nc-tcp-forward.sh $FRONTPORT $BACKHOST $BACKPORT' >&2 | |
exit 1 | |
fi | |
FRONTPORT=$1 | |
BACKHOST=$2 | |
BACKPORT=$3 | |
FIFO=/tmp/backpipe | |
trap 'echo "trapped."; pkill nc; rm -f $FIFO; exit 1' 1 2 3 15 | |
mkfifo $FIFO | |
while true; do | |
nc -l $FRONTPORT <$FIFO | nc $BACKHOST $BACKPORT >$FIFO | |
done | |
rm -f $FIFO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment