SHARE
TWEET

updown_v6.bat

a guest Dec 10th, 2015 29 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. REM UP/DOWN Script for cascading VPN
  2. setlocal enableextensions enabledelayedexpansion
  3.  
  4. IF !script_context! == init GOTO INIT
  5. IF !script_type! == down GOTO INIT
  6. GOTO DONE
  7.  
  8. :INIT
  9.     set vpn_server_ip=%route_network_1%  
  10.     IF !script_type! == up GOTO UP
  11.     GOTO DOWN
  12.  
  13. :DOWN
  14.    
  15.     REM IP DOWN
  16.     if !hop_id! == 1 GOTO DOWN_1
  17.     if !hop_id! == 2 GOTO DOWN_2
  18.     if !hop_id! == 3 GOTO DOWN_3
  19.     if !hop_id! == 4 GOTO DOWN_4
  20.     GOTO DONE
  21.    
  22.     :DOWN_1
  23.         route delete 0.0.0.0 mask 128.0.0.0
  24.         route delete 128.0.0.0 mask 128.0.0.0  
  25.         netsh.exe interface ipv6 delete route 2000::/4 "%dev%" fe80::8
  26.         netsh.exe interface ipv6 delete route 3000::/4 "%dev%" fe80::8
  27.        
  28.     :DOWN_2
  29.         for /l %%x in (0, 64, 223) do (
  30.             route delete %%x.0.0.0 mask 192.0.0.0
  31.         )
  32.         netsh.exe interface ipv6 delete route 2000::/5 "%dev%" fe80::8
  33.         netsh.exe interface ipv6 delete route 2800::/5 "%dev%" fe80::8
  34.         netsh.exe interface ipv6 delete route 3000::/5 "%dev%" fe80::8
  35.         netsh.exe interface ipv6 delete route 3800::/5 "%dev%" fe80::8
  36.        
  37.     :DOWN_3    
  38.         for /l %%x in (0, 32, 223) do (
  39.             route delete %%x.0.0.0 mask 224.0.0.0  
  40.         )
  41.         netsh.exe interface ipv6 delete route 2000::/6 "%dev%" fe80::8
  42.         netsh.exe interface ipv6 delete route 2400::/6 "%dev%" fe80::8
  43.         netsh.exe interface ipv6 delete route 2800::/6 "%dev%" fe80::8
  44.         netsh.exe interface ipv6 delete route 2c00::/6 "%dev%" fe80::8
  45.         netsh.exe interface ipv6 delete route 3000::/6 "%dev%" fe80::8
  46.         netsh.exe interface ipv6 delete route 3400::/6 "%dev%" fe80::8
  47.         netsh.exe interface ipv6 delete route 3800::/6 "%dev%" fe80::8
  48.         netsh.exe interface ipv6 delete route 3c00::/6 "%dev%" fe80::8
  49.        
  50.                
  51.     :DOWN_4
  52.         for /l %%x in (0, 16, 223) do (
  53.             route delete %%x.0.0.0 mask 240.0.0.0  
  54.         )
  55.         netsh.exe interface ipv6 delete route 2000::/7 "%dev%" fe80::8
  56.         netsh.exe interface ipv6 delete route 2200::/7 "%dev%" fe80::8
  57.         netsh.exe interface ipv6 delete route 2400::/7 "%dev%" fe80::8
  58.         netsh.exe interface ipv6 delete route 2600::/7 "%dev%" fe80::8
  59.         netsh.exe interface ipv6 delete route 2800::/7 "%dev%" fe80::8
  60.         netsh.exe interface ipv6 delete route 2a00::/7 "%dev%" fe80::8
  61.         netsh.exe interface ipv6 delete route 2c00::/7 "%dev%" fe80::8
  62.         netsh.exe interface ipv6 delete route 2e00::/7 "%dev%" fe80::8
  63.         netsh.exe interface ipv6 delete route 3000::/7 "%dev%" fe80::8
  64.         netsh.exe interface ipv6 delete route 3200::/7 "%dev%" fe80::8
  65.         netsh.exe interface ipv6 delete route 3400::/7 "%dev%" fe80::8
  66.         netsh.exe interface ipv6 delete route 3600::/7 "%dev%" fe80::8
  67.         netsh.exe interface ipv6 delete route 3800::/7 "%dev%" fe80::8
  68.         netsh.exe interface ipv6 delete route 3a00::/7 "%dev%" fe80::8
  69.         netsh.exe interface ipv6 delete route 3c00::/7 "%dev%" fe80::8
  70.         netsh.exe interface ipv6 delete route 3e00::/7 "%dev%" fe80::8
  71.         GOTO DOWN_DEFAULT
  72.  
  73.     :DOWN_DEFAULT
  74.         route delete %vpn_server_ip% mask 255.255.255.255
  75.    
  76.     GOTO DONE
  77.  
  78.  
  79.  
  80. :UP
  81.    REM IP UP
  82.     if !hop_id! == 1 GOTO UP_1
  83.     if !hop_id! == 2 GOTO UP_2
  84.     if !hop_id! == 3 GOTO UP_3
  85.     if !hop_id! == 4" GOTO UP_4
  86.     GOTO DONE
  87.    
  88.     :UP_1
  89.         call:FINDGATEWAY 0.0.0.0
  90.         call:UP_DEFAULT
  91.         route add 0.0.0.0 mask 128.0.0.0 %route_vpn_gateway%
  92.         route add 128.0.0.0 mask 128.0.0.0 %route_vpn_gateway%
  93.         netsh.exe interface ipv6 add route 2000::/4 "%dev%" fe80::8
  94.         netsh.exe interface ipv6 add route 3000::/4 "%dev%" fe80::8
  95.         GOTO DONE        
  96.     :UP_2  
  97.         call:FINDGATEWAY 128.0.0.0
  98.         call:UP_DEFAULT
  99.         for /l %%x in (0, 64, 223) do (
  100.             route add %%x.0.0.0 mask 192.0.0.0 %route_vpn_gateway%
  101.         )
  102.         netsh.exe interface ipv6 add route 2000::/5 "%dev%" fe80::8
  103.         netsh.exe interface ipv6 add route 2800::/5 "%dev%" fe80::8
  104.         netsh.exe interface ipv6 add route 3000::/5 "%dev%" fe80::8
  105.         netsh.exe interface ipv6 add route 3800::/5 "%dev%" fe80::8
  106.         GOTO DONE
  107.        
  108.     :UP_3
  109.         call:FINDGATEWAY 192.0.0.0
  110.         call:UP_DEFAULT
  111.         for /l %%x in (0, 32, 223) do (
  112.             route add %%x.0.0.0 mask 224.0.0.0 %route_vpn_gateway%
  113.         )
  114.         netsh.exe interface ipv6 add route 2000::/6 "%dev%" fe80::8
  115.         netsh.exe interface ipv6 add route 2400::/6 "%dev%" fe80::8
  116.         netsh.exe interface ipv6 add route 2800::/6 "%dev%" fe80::8
  117.         netsh.exe interface ipv6 add route 2c00::/6 "%dev%" fe80::8
  118.         netsh.exe interface ipv6 add route 3000::/6 "%dev%" fe80::8
  119.         netsh.exe interface ipv6 add route 3400::/6 "%dev%" fe80::8
  120.         netsh.exe interface ipv6 add route 3800::/6 "%dev%" fe80::8
  121.         netsh.exe interface ipv6 add route 3c00::/6 "%dev%" fe80::8
  122.         GOTO DONE
  123.        
  124.     :UP_4    
  125.         call:FINDGATEWAY 224.0.0.0
  126.         call:UP_DEFAULT
  127.         for /l %%x in (0, 16, 223) do (
  128.             route add %%x.0.0.0 mask 240.0.0.0 %route_vpn_gateway%
  129.         )    
  130.         netsh.exe interface ipv6 add route 2000::/7 "%dev%" fe80::8
  131.         netsh.exe interface ipv6 add route 2200::/7 "%dev%" fe80::8
  132.         netsh.exe interface ipv6 add route 2400::/7 "%dev%" fe80::8
  133.         netsh.exe interface ipv6 add route 2600::/7 "%dev%" fe80::8
  134.         netsh.exe interface ipv6 add route 2800::/7 "%dev%" fe80::8
  135.         netsh.exe interface ipv6 add route 2a00::/7 "%dev%" fe80::8
  136.         netsh.exe interface ipv6 add route 2c00::/7 "%dev%" fe80::8
  137.         netsh.exe interface ipv6 add route 2e00::/7 "%dev%" fe80::8
  138.         netsh.exe interface ipv6 add route 3000::/7 "%dev%" fe80::8
  139.         netsh.exe interface ipv6 add route 3200::/7 "%dev%" fe80::8
  140.         netsh.exe interface ipv6 add route 3400::/7 "%dev%" fe80::8
  141.         netsh.exe interface ipv6 add route 3600::/7 "%dev%" fe80::8
  142.         netsh.exe interface ipv6 add route 3800::/7 "%dev%" fe80::8
  143.         netsh.exe interface ipv6 add route 3a00::/7 "%dev%" fe80::8
  144.         netsh.exe interface ipv6 add route 3c00::/7 "%dev%" fe80::8
  145.         netsh.exe interface ipv6 add route 3e00::/7 "%dev%" fe80::8
  146.         GOTO DONE
  147.  
  148.     :UP_DEFAULT
  149.         route add %vpn_server_ip% mask 255.255.255.255 %default_gw%  
  150.         goto :eof
  151.        
  152.     GOTO DONE
  153.      
  154.  
  155.  
  156. :FINDGATEWAY
  157.     set findmask=%~1
  158.     route print -4 | findstr "0.0.0.0"  > hops.file
  159.     set /a linecnt=0
  160.     for /f "delims=" %%i in (hops.file) do (    
  161.         for /f "tokens=1,2,3,4 delims= " %%a in ("%%i") do (
  162.             set ip=%%a
  163.             set netmask=%%b
  164.             set gateway=%%c
  165.             set network=%%d
  166.         )
  167.         if !ip! == 0.0.0.0 (
  168.             if !netmask! == !findmask! (
  169.                 set str=empty
  170.                 for /f "delims=" %%a in ('echo !network! ^|findstr -r .*\..*\..*\..*') do @set str=%%a
  171.                 if NOT !str! == empty (
  172.                     set default_gw=!gateway!
  173.                     goto :eof
  174.                 )
  175.             )
  176.         )
  177.     )
  178.     del hops.file
  179.   goto :eof  
  180.  
  181.  
  182. :DONE
  183.  
  184. endlocal
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top