Skip to content

Instantly share code, notes, and snippets.

@dangtrinhnt
Created May 3, 2020 14:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dangtrinhnt/821eb6b513ce27cf213f5aa019b969b2 to your computer and use it in GitHub Desktop.
Save dangtrinhnt/821eb6b513ce27cf213f5aa019b969b2 to your computer and use it in GitHub Desktop.
Create a sock proxy at a random port that helps you to connect to a private network from your computer
#! /bin/bash
SSH_KEY=$1
BASTION_IP=$2
USERNAME=$3
PROXY_PORT=`comm -23 <(seq 13000 13999 | sort) <(netstat -tan | awk '{print $4}' | cut -d':' -f2 | sort -u) | shuf | head -n 1`
ssh -i "$SSH_KEY" -CND "${PROXY_PORT}" -q "${USERNAME}@${BASTION_IP}" &
echo "socks5://localhost:$PROXY_PORT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment