Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- REM UP/DOWN Script for cascading VPN
- setlocal enableextensions enabledelayedexpansion
- IF !script_context! == init GOTO INIT
- IF !script_type! == down GOTO INIT
- GOTO DONE
- :INIT
- set vpn_server_ip=%route_network_1%
- IF !script_type! == up GOTO UP
- GOTO DOWN
- :DOWN
- REM IP DOWN
- if !hop_id! == 1 GOTO DOWN_1
- if !hop_id! == 2 GOTO DOWN_2
- if !hop_id! == 3 GOTO DOWN_3
- if !hop_id! == 4 GOTO DOWN_4
- GOTO DONE
- :DOWN_1
- route delete 0.0.0.0 mask 128.0.0.0
- route delete 128.0.0.0 mask 128.0.0.0
- netsh.exe interface ipv6 delete route 2000::/4 "%dev%" fe80::8
- netsh.exe interface ipv6 delete route 3000::/4 "%dev%" fe80::8
- :DOWN_2
- for /l %%x in (0, 64, 223) do (
- route delete %%x.0.0.0 mask 192.0.0.0
- )
- netsh.exe interface ipv6 delete route 2000::/5 "%dev%" fe80::8
- netsh.exe interface ipv6 delete route 2800::/5 "%dev%" fe80::8
- netsh.exe interface ipv6 delete route 3000::/5 "%dev%" fe80::8
- netsh.exe interface ipv6 delete route 3800::/5 "%dev%" fe80::8
- :DOWN_3
- for /l %%x in (0, 32, 223) do (
- route delete %%x.0.0.0 mask 224.0.0.0
- )
- netsh.exe interface ipv6 delete route 2000::/6 "%dev%" fe80::8
- netsh.exe interface ipv6 delete route 2400::/6 "%dev%" fe80::8
- netsh.exe interface ipv6 delete route 2800::/6 "%dev%" fe80::8
- netsh.exe interface ipv6 delete route 2c00::/6 "%dev%" fe80::8
- netsh.exe interface ipv6 delete route 3000::/6 "%dev%" fe80::8
- netsh.exe interface ipv6 delete route 3400::/6 "%dev%" fe80::8
- netsh.exe interface ipv6 delete route 3800::/6 "%dev%" fe80::8
- netsh.exe interface ipv6 delete route 3c00::/6 "%dev%" fe80::8
- :DOWN_4
- for /l %%x in (0, 16, 223) do (
- route delete %%x.0.0.0 mask 240.0.0.0
- )
- netsh.exe interface ipv6 delete route 2000::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 delete route 2200::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 delete route 2400::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 delete route 2600::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 delete route 2800::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 delete route 2a00::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 delete route 2c00::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 delete route 2e00::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 delete route 3000::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 delete route 3200::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 delete route 3400::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 delete route 3600::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 delete route 3800::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 delete route 3a00::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 delete route 3c00::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 delete route 3e00::/7 "%dev%" fe80::8
- GOTO DOWN_DEFAULT
- :DOWN_DEFAULT
- route delete %vpn_server_ip% mask 255.255.255.255
- GOTO DONE
- :UP
- REM IP UP
- if !hop_id! == 1 GOTO UP_1
- if !hop_id! == 2 GOTO UP_2
- if !hop_id! == 3 GOTO UP_3
- if !hop_id! == 4" GOTO UP_4
- GOTO DONE
- :UP_1
- call:FINDGATEWAY 0.0.0.0
- call:UP_DEFAULT
- route add 0.0.0.0 mask 128.0.0.0 %route_vpn_gateway%
- route add 128.0.0.0 mask 128.0.0.0 %route_vpn_gateway%
- netsh.exe interface ipv6 add route 2000::/4 "%dev%" fe80::8
- netsh.exe interface ipv6 add route 3000::/4 "%dev%" fe80::8
- GOTO DONE
- :UP_2
- call:FINDGATEWAY 128.0.0.0
- call:UP_DEFAULT
- for /l %%x in (0, 64, 223) do (
- route add %%x.0.0.0 mask 192.0.0.0 %route_vpn_gateway%
- )
- netsh.exe interface ipv6 add route 2000::/5 "%dev%" fe80::8
- netsh.exe interface ipv6 add route 2800::/5 "%dev%" fe80::8
- netsh.exe interface ipv6 add route 3000::/5 "%dev%" fe80::8
- netsh.exe interface ipv6 add route 3800::/5 "%dev%" fe80::8
- GOTO DONE
- :UP_3
- call:FINDGATEWAY 192.0.0.0
- call:UP_DEFAULT
- for /l %%x in (0, 32, 223) do (
- route add %%x.0.0.0 mask 224.0.0.0 %route_vpn_gateway%
- )
- netsh.exe interface ipv6 add route 2000::/6 "%dev%" fe80::8
- netsh.exe interface ipv6 add route 2400::/6 "%dev%" fe80::8
- netsh.exe interface ipv6 add route 2800::/6 "%dev%" fe80::8
- netsh.exe interface ipv6 add route 2c00::/6 "%dev%" fe80::8
- netsh.exe interface ipv6 add route 3000::/6 "%dev%" fe80::8
- netsh.exe interface ipv6 add route 3400::/6 "%dev%" fe80::8
- netsh.exe interface ipv6 add route 3800::/6 "%dev%" fe80::8
- netsh.exe interface ipv6 add route 3c00::/6 "%dev%" fe80::8
- GOTO DONE
- :UP_4
- call:FINDGATEWAY 224.0.0.0
- call:UP_DEFAULT
- for /l %%x in (0, 16, 223) do (
- route add %%x.0.0.0 mask 240.0.0.0 %route_vpn_gateway%
- )
- netsh.exe interface ipv6 add route 2000::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 add route 2200::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 add route 2400::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 add route 2600::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 add route 2800::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 add route 2a00::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 add route 2c00::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 add route 2e00::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 add route 3000::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 add route 3200::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 add route 3400::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 add route 3600::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 add route 3800::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 add route 3a00::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 add route 3c00::/7 "%dev%" fe80::8
- netsh.exe interface ipv6 add route 3e00::/7 "%dev%" fe80::8
- GOTO DONE
- :UP_DEFAULT
- route add %vpn_server_ip% mask 255.255.255.255 %default_gw%
- goto :eof
- GOTO DONE
- :FINDGATEWAY
- set findmask=%~1
- route print -4 | findstr "0.0.0.0" > hops.file
- set /a linecnt=0
- for /f "delims=" %%i in (hops.file) do (
- for /f "tokens=1,2,3,4 delims= " %%a in ("%%i") do (
- set ip=%%a
- set netmask=%%b
- set gateway=%%c
- set network=%%d
- )
- if !ip! == 0.0.0.0 (
- if !netmask! == !findmask! (
- set str=empty
- for /f "delims=" %%a in ('echo !network! ^|findstr -r .*\..*\..*\..*') do @set str=%%a
- if NOT !str! == empty (
- set default_gw=!gateway!
- goto :eof
- )
- )
- )
- )
- del hops.file
- goto :eof
- :DONE
- endlocal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement