Skip to content

Use Random Port Selection to Bypass Locked Default VPN Port on Windows #267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion wsl-vpnkit
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,31 @@ fi
# replace calls to iptables if iptables-legacy exists
command -v iptables-legacy >/dev/null && alias iptables=iptables-legacy

# Choose random free SSH port for GVPROXY by default
get_random_port() {
# Random the range
min=49152
max=65535

# Keep looping until finded usable port
while true; do
port=$(shuf -i $min-$max -n 1)

# Check if port is been using
if ! ss -tan4H | grep -qE "LISTEN.*:$port\b"; then
break
fi
done

echo "$port"
}

run () {
echo "starting vm and gvproxy..."
PORT=$(get_random_port)
echo "using port: $PORT"
$VMEXEC_PATH \
-url="stdio:$GVPROXY_PATH?listen-stdio=accept&debug=$DEBUG" \
-url="stdio:$GVPROXY_PATH?listen-stdio=accept&ssh-port=$PORT&debug=$DEBUG" \
-iface="$TAP_NAME" \
-stop-if-exist="" \
-preexisting=1 \
Expand Down