Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
"name": "PowerShell Launch Current File",
"type": "PowerShell",
"request": "launch",
"script": "sudo ${file}",
"cwd": "${cwd}"
"script": "${file}",
"cwd": "${workspaceFolder}",
"createTemporaryIntegratedConsole": true,
"args": ["-ExecutionPolicy", "Bypass"]
}
]
}
80 changes: 12 additions & 68 deletions run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
所有规则统一归入分组 "DisableSogouNetwork",便于批量管理与精准删除。
重复运行前会自动清除同组旧规则,确保幂等性,不会造成规则膨胀。

可选功能:阻断 v2rayN 本地代理绕过。
当用户启用 v2rayN 等代理软件后,搜狗输入法可能通过连接本机回环代理端口(如 Mixed Port)
将网络请求转交给代理进程,从而绕过按程序阻断的策略。
启用此功能(BlockV2rayNProxyBypass)后,脚本会额外为每个 exe 创建一条出站阻断规则,
禁止其连接 127.0.0.1 上指定的代理端口(默认覆盖 10808、10811、10812、10813)。
# 该脚本通过创建 Windows 防火墙阻止规则,阻断指定目录及其子目录中所有 .exe 文件的网络连接。

.PARAMETER MainFolder
主目录路径。若不传入,脚本将交互提示,直接回车使用默认值
Expand All @@ -29,44 +25,26 @@
Both - 同时阻断入站和出站(默认)
OutboundOnly - 仅阻断出站

.PARAMETER BlockV2rayNProxyBypass
是否启用 v2rayN 本地代理绕过阻断(默认 $true)。
启用后,会额外为每个 exe 创建一条 IPv4(127.0.0.1)出站阻断规则,
禁止其连接本机回环地址上的 v2rayN 代理端口,防止通过代理绕过联网限制。

.PARAMETER V2rayNMixedPort
v2rayN 的 Mixed Port 端口号(默认 10808)。
与 V2rayNExtraPortOffsets 共同决定需要阻断的端口集合。

.PARAMETER V2rayNExtraPortOffsets
相对于 V2rayNMixedPort 的偏移量列表(默认 @(3, 4, 5))。
默认偏移对应:PAC Port(+3=10811)、Xray API(+4=10812)、mihomo API(+5=10813)。
# 额外参数请见脚本头部说明

.EXAMPLE
.\run.ps1
# 交互式输入,回车使用默认路径,同时阻断入站+出站,并启用 v2rayN 绕过阻断
# 交互式输入,回车使用默认路径,同时阻断入站+出站

.EXAMPLE
.\run.ps1 -MainFolder "D:\SogouInput" -DirectionMode OutboundOnly
# 指定目录,仅阻断出站流量,并启用 v2rayN 绕过阻断

.EXAMPLE
.\run.ps1 -BlockV2rayNProxyBypass $false
# 禁用 v2rayN 绕过阻断,仅保留原有防火墙规则
# 指定目录,仅阻断出站流量

.EXAMPLE
.\run.ps1 -V2rayNMixedPort 7890 -V2rayNExtraPortOffsets @(1, 2)
# 使用自定义 Mixed Port 7890,额外阻断 7891、7892 端口
.\run.ps1 -MainFolder "D:\SogouInput" -DirectionMode OutboundOnly
# 指定目录,仅阻断出站流量
#>

param (
[string] $MainFolder = '',
[string[]] $ExtraFolders = @('C:\Windows\SysWOW64\IME\SogouPY'),
[ValidateSet('Both', 'OutboundOnly')]
[string] $DirectionMode = 'Both',
[bool] $BlockV2rayNProxyBypass = $true,
[int] $V2rayNMixedPort = 10808,
[int[]] $V2rayNExtraPortOffsets = @(3, 4, 5)
[string] $DirectionMode = 'Both'
)

$script:GroupName = 'DisableSogouNetwork'
Expand All @@ -81,11 +59,7 @@ function Add-BlockRule {
[string] $FolderPath,

[ValidateSet('Both', 'OutboundOnly')]
[string] $Mode = 'Both',

[bool] $BlockV2rayNProxyBypass = $true,
[int] $V2rayNMixedPort = 10808,
[int[]] $V2rayNExtraPortOffsets = @(3, 4, 5)
[string] $Mode = 'Both'
)

if (-not (Test-Path -Path $FolderPath -PathType Container)) {
Expand Down Expand Up @@ -118,11 +92,6 @@ function Add-BlockRule {
$addedRules = 0
$addedFiles = 0

# 预计算 v2rayN 本地代理绕过阻断端口(本次循环所有 exe 共用)
$loopbackPorts = $null
if ($BlockV2rayNProxyBypass) {
$loopbackPorts = @([string]$V2rayNMixedPort) + ($V2rayNExtraPortOffsets | ForEach-Object { [string]($V2rayNMixedPort + $_) })
}

# 需要禁用的更新程序列表
$exeList = @("SOGOUSmartAssistant.exe", "SogouPlayLauncher.exe", "SGWangzai.exe", "SGSmartAssistant.exe", "SGDownload.exe", "PinyinUp.exe")
Expand Down Expand Up @@ -168,20 +137,7 @@ function Add-BlockRule {
$addedRules++
}

# v2rayN 本地代理绕过阻断规则(IPv4):禁止该 exe 连接本机 IPv4 回环代理端口
if ($BlockV2rayNProxyBypass) {
New-NetFirewallRule `
-DisplayName "$script:GroupName - $($file.FullName) [BlockV2rayNLoopback IPv4]" `
-Group $script:GroupName `
-Direction Outbound `
-Program $file.FullName `
-Protocol TCP `
-RemoteAddress '127.0.0.1' `
-RemotePort $loopbackPorts `
-Action Block `
-ErrorAction Stop | Out-Null
$addedRules++
}
# (不再创建针对本机回环代理的额外阻断规则)

$addedFiles++
Write-Host " [+] $($file.Name)" -ForegroundColor Green
Expand All @@ -208,28 +164,16 @@ Write-Host '=== 开始禁用搜狗输入法网络访问 ===' -ForegroundColor Ye
Write-Host "主目录 :$MainFolder" -ForegroundColor Cyan
Write-Host "方向模式 :$DirectionMode" -ForegroundColor Cyan
Write-Host "规则分组 :$script:GroupName" -ForegroundColor Cyan
if ($BlockV2rayNProxyBypass) {
$loopbackPortsInfo = @($V2rayNMixedPort) + ($V2rayNExtraPortOffsets | ForEach-Object { $V2rayNMixedPort + $_ })
Write-Host "v2rayN绕过阻断:已启用(MixedPort:$V2rayNMixedPort,阻断端口:$($loopbackPortsInfo -join ', '))" -ForegroundColor Cyan
}
else {
Write-Host "v2rayN绕过阻断:已禁用" -ForegroundColor Cyan
}
Write-Host ''
Write-Host ''

# 处理主目录
Add-BlockRule -FolderPath $MainFolder -Mode $DirectionMode `
-BlockV2rayNProxyBypass $BlockV2rayNProxyBypass `
-V2rayNMixedPort $V2rayNMixedPort `
-V2rayNExtraPortOffsets $V2rayNExtraPortOffsets
Add-BlockRule -FolderPath $MainFolder -Mode $DirectionMode

# 处理额外目录(不存在时仅警告,不中断)
foreach ($folder in $ExtraFolders) {
Write-Host ''
Add-BlockRule -FolderPath $folder -Mode $DirectionMode `
-BlockV2rayNProxyBypass $BlockV2rayNProxyBypass `
-V2rayNMixedPort $V2rayNMixedPort `
-V2rayNExtraPortOffsets $V2rayNExtraPortOffsets
Add-BlockRule -FolderPath $folder -Mode $DirectionMode
}

Write-Host ''
Expand Down
Loading