windows_wireguard.bat

@echo off
::# DESC: Skript zur Steuerung des WireGuard Tunnels
::# KONFIGURATION
set "TARGET_IP=192.168.192.1"
set "SERVICE_NAME=GG310"
set "WG_PATH=C:\Program Files\WireGuard"

:: Check for administrative privileges
net session >nul 2>&1
if %errorLevel% neq 0 (
    echo Requesting administrative privileges...
    powershell -Command "Start-Process '%~f0' -Verb RunAs"
    exit /b
)

:CHECK_STATUS
:: Check for output text from wg.exe
"%WG_PATH%\wg.exe" show | findstr "." >nul 2>&1

if %errorLevel% equ 0 (
    goto TUNNEL_ACTIVE
) else (
    goto TUNNEL_INACTIVE
)

:TUNNEL_ACTIVE
cls
echo [STATUS] Wireguard tunnel %SERVICE_NAME% is ACTIVE.
echo --------------------------------------------------
:: Display the tunnel diagnostics
"%WG_PATH%\wg.exe" show
echo --------------------------------------------------
echo.
echo 1. Ping %TARGET_IP% (3 times)
echo 2. Stop Tunnel and Exit
echo 3. Exit Script
echo.
set /p choice="Select an option (1-3): "

if "%choice%"=="1" (
    ping %TARGET_IP% -n 3
    echo.
    echo Ping complete.
    pause
    goto TUNNEL_ACTIVE
)
if "%choice%"=="2" (
    echo Stopping tunnel...
    "%WG_PATH%\wireguard.exe" /uninstalltunnelservice %SERVICE_NAME%
    exit
)
if "%choice%"=="3" exit
goto TUNNEL_ACTIVE

:TUNNEL_INACTIVE
cls
echo [STATUS] Wireguard tunnel %SERVICE_NAME% is NOT active.
echo.
echo 1. Start Tunnel and Ping
echo 2. Exit Script
echo.
set /p choice="Select an option (1-2): "

if "%choice%"=="1" (
    echo Starting tunnel...
    "%WG_PATH%\wireguard.exe" /installtunnelservice "%WG_PATH%\Data\Configurations\%SERVICE_NAME%.conf.dpapi"
    
    :: Pause briefly to allow handshake
    timeout /t 3 >nul
    
    :: Show diagnostics now that it's up
    echo.
    echo Tunnel started. Current Configuration:
    "%WG_PATH%\wg.exe" show
    echo.
    
    echo Pinging gateway %TARGET_IP%...
    ping %TARGET_IP% -n 3
    echo.
    pause
    
    :: Redirect back to Active menu instead of exiting
    goto TUNNEL_ACTIVE
)
if "%choice%"=="2" exit
goto TUNNEL_INACTIVE
    
Zurück zur Übersicht