Created
September 1, 2015 07:12
-
-
Save icedraco/793410f8e66018a56fbf to your computer and use it in GitHub Desktop.
BASH Proxy / Relay using NetCat
This file contains hidden or 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 | |
| # Adapted from the script on: | |
| # http://notes.tweakblogs.net/blog/7955/ | |
| TMP=$HOME/tmp | |
| PREFIX=proxy | |
| FIFO=`mktemp -u -p $TMP -t $PREFIX.XXXXXXXXXXX` | |
| # Check arguments | |
| if [ $# -lt 3 ] | |
| then | |
| echo "Syntax: $0 <localport> <target_addr> <target_port>" | |
| exit 1 | |
| else | |
| LOCAL_PORT=$1 | |
| TARGET_ADDR=$2 | |
| TARGET_PORT=$3 | |
| fi | |
| # Initialization | |
| rm -v $TMP/$PREFIX.* | |
| echo | |
| echo "--> Running proxy: *:$LOCAL_PORT => $TARGET_ADDR:$TARGET_PORT" | |
| trap 'rm -f "$FIFO"' EXIT | |
| mkfifo $FIFO | |
| nc -l -k -p $LOCAL_PORT <$FIFO |nc $TARGET_ADDR $TARGET_PORT >$FIFO | |
| rm $FIFO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment