Created
August 14, 2021 15:55
-
-
Save cqjjjzr/06ed1d9e3fffd0bf546c2887688cda94 to your computer and use it in GitHub Desktop.
EasyConnectFix Powershell版:用于 EasyConnect 连接到南京大学 VPN 后,删除无用路由以防止连接南大校内资源以外的流量经过校园网 VPN 而导致速度下降。
This file contains 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
# 用于 EasyConnect 连接到南京大学 VPN 后,删除无用路由以防止连接南大校内资源以外的流量经过校园网 VPN 而导致速度下降。 | |
# Usage: 在 EasyConnect 连接到南京大学 VPN 后,**以管理员身份**运行此脚本。 | |
# 子网前缀抄自 https://github.com/tangruize/NJU-EasyConnect-Script | |
# 缺陷;断开 EasyConnect 后,创建的路由并不会删除,这可能导致断开后访问南大网站出现异常(实测统一认证上不去了)。 | |
$routes = Get-NetRoute -AddressFamily IPv4 | Where-Object { $_.NextHop.StartsWith("172.29") } | |
if ($routes.Count -eq 0) { | |
Write-Host "No NJU route found! exiting..." | |
exit | |
} | |
$defaultGateway = $routes[0].NextHop | |
$interface = $routes[0].InterfaceIndex | |
# remove NJU default routes first | |
$routes | Remove-NetRoute -Confirm:$false | |
# 南大IP | |
$subnets = "36.152.24.0/24 58.192.32.0/20 58.192.48.0/21 58.193.224.0/19 58.240.127.0/27 112.25.191.64/26 114.212.0.0/16 172.0.0.0/8 180.209.0.0/20 202.38.2.0/23 202.38.126.160/28 202.119.32.0/19 202.127.247.0/24 210.28.0.0/14 211.162.26.0/27 211.162.81.0/25 218.94.142.0/24 219.219.112.0/20 221.6.40.128/25 222.94.3.0/24 222.94.208.0/24" | |
$subnets += " " | |
# 图书馆电子资源 | |
$subnets += "122.115.32.0/19 101.230.240.0/20 42.62.48.0/20 42.62.64.0/18 140.210.64.0/19 183.84.0.0/21 103.88.33.0/24 23.33.94.0/24 162.159.129.0/24 34.107.128.0/24 140.234.252.0/24 151.101.228.0/22 104.18.0.0/24 195.128.8.0/24 151.101.0.0/16 104.18.20.0/24 47.114.157.0/24" | |
$subnets = $subnets.Split(" ") | |
foreach ($submet in $subnets) { | |
$trimmedSubnet = $submet.Trim() | |
if ($trimmedSubnet.Length -eq 0) { | |
continue | |
} | |
try { | |
Get-NetRoute -DestinationPrefix $trimmedSubnet -ErrorAction SilentlyContinue | Remove-NetRoute -Confirm:$false | |
} catch {} | |
try { | |
Get-NetRoute -DestinationPrefix $trimmedSubnet -PolicyStore PersistentStore -ErrorAction SilentlyContinue | Remove-NetRoute -Confirm:$false | |
} catch {} | |
New-NetRoute -AddressFamily IPv4 -DestinationPrefix $trimmedSubnet -InterfaceIndex $interface -NextHop $defaultGateway -PolicyStore ActiveStore | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment