Skip to content
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

Choose random free SSH port for GVPROXY #266

Open
wants to merge 1 commit 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
17 changes: 16 additions & 1 deletion wsl-vpnkit
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,25 @@ 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() {
# starting from BASE_PORT with INCREMENT step
BASE_PORT=2222 # the default SSH port chosen if free
INCREMENT=1

port=$BASE_PORT

while [ -n "$(ss -tan4H "sport = $port")" ]; do
port=$((port+INCREMENT))
done

echo "$port"
}

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