Skip to content

Instantly share code, notes, and snippets.

@icedraco
Created September 1, 2015 07:12
Show Gist options
  • Select an option

  • Save icedraco/793410f8e66018a56fbf to your computer and use it in GitHub Desktop.

Select an option

Save icedraco/793410f8e66018a56fbf to your computer and use it in GitHub Desktop.
BASH Proxy / Relay using NetCat
#!/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