Created
April 5, 2024 08:28
-
-
Save zoghal/a14fac22ac44de7b41894c4c2114caf5 to your computer and use it in GitHub Desktop.
My socks2vpn.bat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
SET "SCRIPT=%0" | |
SET "ARG=%1" | |
SET "GATEWAY=192.168.1.1" | |
SET "SERVER_ADDRESS=162.159.192.193" | |
SET "SOCKS_SCHEME=socks5" | |
SET "SOCKS_ADDRESS=127.0.0.1" | |
SET "SOCKS_PORT=8086" | |
SET "TUN_NAME=wintun" | |
SET "TUN_ADDRESS=10.10.10.10" | |
SET "TUN_SUBNET=255.255.255.0" | |
SET "TUN_PRIMARY_DNS=8.8.8.8" | |
SET "TUN_SECONDARY_DNS=8.8.4.4" | |
SET "TUN_POST_UP=.\%SCRIPT% t" | |
SET "OS_DEFAULT_ROUTE=0.0.0.0 MASK 0.0.0.0 %GATEWAY%" | |
SET "TUN_ROUTE=0.0.0.0 MASK 0.0.0.0 %TUN_ADDRESS% METRIC 1" | |
SET "SERVER_ROUTE=%SERVER_ADDRESS% MASK 255.255.255.255 %GATEWAY% METRIC 10" | |
SET "RESTORE_DEFAULT_ROUTE=.\%SCRIPT% r" | |
if "%ARG%" == "t" ( | |
netsh interface ip set address name=%TUN_NAME% source=static addr=%TUN_ADDRESS% mask=%TUN_SUBNET% gateway=none | |
netsh interface ip set dns name=%TUN_NAME% source=static address=%TUN_PRIMARY_DNS% register=primary | |
netsh interface ip add dns name=%TUN_NAME% address=%TUN_SECONDARY_DNS% index=2 | |
goto :eof | |
) | |
if "%ARG%" == "r" ( | |
echo: | |
echo "Performing cleanup..." | |
taskkill /F /IM tun2socks.exe | |
taskkill /F /IM warp-plus.exe | |
route DELETE %SERVER_ROUTE% | |
route DELETE %TUN_ROUTE% | |
route -p ADD %OS_DEFAULT_ROUTE% METRIC 1 | |
echo: | |
echo "OS default route restored" | |
goto :eof | |
) | |
:: We need to delete OS default route first | |
route DELETE %OS_DEFAULT_ROUTE% | |
:: Route all trafic to the tun device | |
route -p ADD %TUN_ROUTE% | |
:: Exclude proxy server itself | |
route -p ADD %SERVER_ROUTE% | |
:: Run your proxy in background | |
start /B warp-plus.exe -k tH057a1i-5v367oFK-4Jj267Cx -e 162.159.192.193:945 --gool | |
:: To setup tun device we need wintun | |
:: You can get it from here: https://www.wintun.net | |
:: You must put wintun.dll file in tun2socks dir | |
start /B tun2socks -device %TUN_NAME% -proxy %SOCKS_SCHEME%://%SOCKS_ADDRESS%:%SOCKS_PORT% -tun-post-up "%TUN_POST_UP%" -tcp-auto-tuning | |
SET trap= | |
for /f "usebackq delims=" %%a in (`"prompt $h & for %%b in (1) do REM Press Ctrl+C twice to exit"`) do SET "bs=%%a" | |
SET /p dummy=%bs%||SET trap="catch" | |
if defined trap ( | |
%RESTORE_DEFAULT_ROUTE% | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment