Skip to content

Instantly share code, notes, and snippets.

@andrew-aladjev
Created April 23, 2024 09:50
Show Gist options
  • Save andrew-aladjev/634676352ae743ebadf65744a976857b to your computer and use it in GitHub Desktop.
Save andrew-aladjev/634676352ae743ebadf65744a976857b to your computer and use it in GitHub Desktop.
Wireguard wstunnel
#!/bin/bash
set -e
WG_INTERFACE="$1"
WG_RUN_DIR_PATH="/tmp/run/wireguard"
CONTAINER_ID_PATH="${WG_RUN_DIR_PATH}/wstunnel-${WG_INTERFACE}.container-id"
CONTAINER_ID=$(cat "$CONTAINER_ID_PATH" || :)
if [ ! -z "$CONTAINER_ID" ]; then
docker stop "$CONTAINER_ID" || :
docker rm -f "$CONTAINER_ID" || :
fi
rm -f "$CONTAINER_ID_PATH" || :
#!/bin/bash
set -e
WG_INTERFACE="$1"
WG_RUN_DIR_PATH="/tmp/run/wireguard"
CONTAINER_ID_PATH="${WG_RUN_DIR_PATH}/wstunnel-${WG_INTERFACE}.container-id"
CONTAINER_ID=$(cat "$CONTAINER_ID_PATH" || :)
if [ ! -z "$CONTAINER_ID" ]; then
docker stop "$CONTAINER_ID" || :
docker rm -f "$CONTAINER_ID" || :
fi
rm -f "$CONTAINER_ID_PATH" || :
#!/bin/bash
set -e
WG_INTERFACE="$1"
TCP_HOST="$2"
TCP_PORT="$3"
UDP_PORT="$4"
WG_RUN_DIR_PATH="/tmp/run/wireguard"
mkdir -p "$WG_RUN_DIR_PATH"
IMAGE_NAME="ghcr.io/erebe/wstunnel:latest"
USER_NAME="myuser"
PASSWORD="mypass"
CONTAINER_ID=$(
docker run --rm --detach --network "host" --user "0:0" "$IMAGE_NAME" \
./wstunnel client --log-lvl "INFO" -L "udp://${UDP_PORT}:localhost:${UDP_PORT}?timeout_sec=0" "wss://${USER_NAME}:${PASSWORD}@${TCP_HOST}:${TCP_PORT}"
)
CONTAINER_ID_PATH="${WG_RUN_DIR_PATH}/wstunnel-${WG_INTERFACE}.container-id"
echo "$CONTAINER_ID" > "$CONTAINER_ID_PATH"
#!/bin/bash
set -e
WG_INTERFACE="$1"
TCP_PORT="$2"
UDP_PORT="$3"
WG_RUN_DIR_PATH="/tmp/run/wireguard"
mkdir -p "$WG_RUN_DIR_PATH"
IMAGE_NAME="ghcr.io/erebe/wstunnel:latest"
USER_NAME="myuser"
PASSWORD="mypass"
CONTAINER_ID=$(
docker run --rm --detach --network "host" --user "0:0" "$IMAGE_NAME" \
./wstunnel server --log-lvl "INFO" --restrict-to "localhost:${UDP_PORT}" "wss://${USER_NAME}:${PASSWORD}@[::]:${TCP_PORT}"
)
CONTAINER_ID_PATH="${WG_RUN_DIR_PATH}/wstunnel-${WG_INTERFACE}.container-id"
echo "$CONTAINER_ID" > "$CONTAINER_ID_PATH"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment