Windows网络「SSL错误问题」及解决方案

时间:2025-02-11 14:04:44
# 关键的传入参数 param ( [string]$action = "off", [string]$additionalBypassItems = "", [switch]$help ) # 示例帮助 function Display-Help { Write-Host "Usage of 代理管理.ps1:" Write-Host " To enable proxy: 盘符:\具体路径\代理管理.ps1 -action 'on' -additionalBypassItems ';172.100.*'" Write-Host " To disable proxy: 盘符:\具体路径\代理管理.ps1 -action 'off'" } if ($help) { Display-Help return } # 注册表路径 $registryPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" Write-Host "default registryPath: $registryPath" # 清楚代理 function Clear-Proxy { Set-ItemProperty -Path $registryPath -Name ProxyEnable -Value 0 Remove-ItemProperty -Path $registryPath -Name ProxyServer -ErrorAction SilentlyContinue Remove-ItemProperty -Path $registryPath -Name ProxyOverride -ErrorAction SilentlyContinue Write-Host "Proxy disabled. ProxyEnable set 0, ProxyServer and ProxyOverride is remove." } if ($action -eq "off") { Clear-Proxy return } elseif ($action -eq "on") { } else { Write-Host "Invalid action. Use 'on' to enable or 'off' to disable the proxy." } # 代理服务器地址 $proxyServer = "127.0.0.1:7890" Write-Host "default proxyServer: $proxyServer" # 基本代理排除白名单(本地和内部网络的流量,用分号分隔各个条目) $baseProxyBypassList = "localhost;127.*;10.*;172.16.*;172.17.*;172.18.*;172.19.*;172.20.*;172.21.*;172.22.*;172.23.*;172.24.*;172.25.*;172.26.*;172.27.*;172.28.*;172.29.*;172.30.*;172.31.*;192.168.*;127.0.0.1" Write-Host "default baseProxyBypassList: $baseProxyBypassList" # 宽泛的ip正确性校验 function IsValid-IPAddress($ip) { return $ip -match "^\d{1,3}(\.\d{1,3}|\.\*){0,3}(\.\*)?$" } # 宽泛的domain正确性校验 function IsValid-Domain($domain) { return $domain -match "^((?!-)[A-Za-z0-9-]{1,63}(?<!-)\.)+[A-Za-z]{2,6}$" } # 合并基本白名单和额外的白名单条目 $proxyBypassList = $baseProxyBypassList if ($additionalBypassItems -ne "") { $items = $additionalBypassItems.Split(';') foreach ($item in $items) { $isIPValid = IsValid-IPAddress $item $isDomainValid = IsValid-Domain $item if ($isIPValid -or $isDomainValid) { $proxyBypassList += ";" + $item Write-Host "new additionalBypassItem: $item" } else { Write-Host "Invalid item: $item" } } } # 设置代理 function Set-Proxy { Set-ItemProperty -Path $registryPath -Name ProxyEnable -Value 1 Set-ItemProperty -Path $registryPath -Name ProxyServer -Value $proxyServer Set-ItemProperty -Path $registryPath -Name ProxyOverride -Value $proxyBypassList Write-Host "Proxy enabled. ProxyEnable set 1, ProxyServer and ProxyOverride is set." } # 代理管理 if ($action -eq "on") { Set-Proxy return } elseif ($action -eq "off") { } else { Write-Host "Invalid action. Use 'on' to enable or 'off' to disable the proxy." }