From 05ec945a05e5e11bec21ae82b36ace1da790dfbd Mon Sep 17 00:00:00 2001 From: Petr Osetrov Date: Thu, 26 Mar 2026 07:01:59 +0300 Subject: [PATCH] `test zapret.ps1` dpi suite v2 (#11349) --- utils/test zapret.ps1 | 130 +++++++++++++++++++++--------------------- 1 file changed, 65 insertions(+), 65 deletions(-) diff --git a/utils/test zapret.ps1 b/utils/test zapret.ps1 index abf29bc..db9c7ea 100644 --- a/utils/test zapret.ps1 +++ b/utils/test zapret.ps1 @@ -77,29 +77,25 @@ function Convert-Target { # DPI checker defaults (override via MONITOR_* env vars like in monitor.ps1) $dpiTimeoutSeconds = 5 -$dpiRangeBytes = 262144 -$dpiWarnMinKB = 14 -$dpiWarnMaxKB = 22 +$dpiRangeBytes = 65536 $dpiMaxParallel = 8 -$dpiCustomUrl = $env:MONITOR_URL +$dpiCustomHost = $env:MONITOR_HOST if ($env:MONITOR_TIMEOUT) { [int]$dpiTimeoutSeconds = $env:MONITOR_TIMEOUT } if ($env:MONITOR_RANGE) { [int]$dpiRangeBytes = $env:MONITOR_RANGE } -if ($env:MONITOR_WARN_MINKB) { [int]$dpiWarnMinKB = $env:MONITOR_WARN_MINKB } -if ($env:MONITOR_WARN_MAXKB) { [int]$dpiWarnMaxKB = $env:MONITOR_WARN_MAXKB } if ($env:MONITOR_MAX_PARALLEL) { [int]$dpiMaxParallel = $env:MONITOR_MAX_PARALLEL } function Get-DpiSuite { # Suite sourced from https://github.com/hyperion-cs/dpi-checkers (Apache-2.0 license) # Original copyright retained from dpi-checkers repository - $url = "https://hyperion-cs.github.io/dpi-checkers/ru/tcp-16-20/suite.json" + $url = "https://hyperion-cs.github.io/dpi-checkers/ru/tcp-16-20/suite.v2.json" try { (Invoke-RestMethod -Uri $url -TimeoutSec $dpiTimeoutSeconds) | Select-Object ` @{n='Id'; e={$_.id}}, @{n='Provider'; e={$_.provider}}, - @{n='Url'; e={$_.url}}, - @{n='Times'; e={$_.times}} + @{n='小ountry'; e={$_.country}}, + @{n='Host'; e={$_.host}} } catch { Write-Host "[WARN] Fetch dpi suite failed." -ForegroundColor Yellow @@ -109,23 +105,17 @@ function Get-DpiSuite { function Build-DpiTargets { param( - [string]$CustomUrl + [string]$CustomHost ) $suite = Get-DpiSuite $targets = @() - if ($CustomUrl) { - $targets += @{ Id = "CUSTOM"; Provider = "Custom"; Url = $CustomUrl } + if ($CustomHost) { + $targets += @{ Id = "CUSTOM"; Provider = "Custom"; 小ountry = "馃挕"; Host = $CustomHost } } else { foreach ($entry in $suite) { - $repeat = $entry.Times - if (-not $repeat -or $repeat -lt 1) { $repeat = 1 } - for ($i = 0; $i -lt $repeat; $i++) { - $suffix = "" - if ($repeat -gt 1) { $suffix = "@$i" } - $targets += @{ Id = "$($entry.Id)$suffix"; Provider = $entry.Provider; Url = $entry.Url } - } + $targets += @{ Id = $entry.Id; 小ountry = $entry.小ountry; Provider = $entry.Provider; Host = $entry.Host } } } @@ -137,8 +127,6 @@ function Invoke-DpiSuite { [array]$Targets, [int]$TimeoutSeconds, [int]$RangeBytes, - [int]$WarnMinKB, - [int]$WarnMaxKB, [int]$MaxParallel ) @@ -151,45 +139,57 @@ function Invoke-DpiSuite { $rangeSpec = "0-$($RangeBytes - 1)" $warnDetected = $false - Write-Host "[INFO] Targets: $($Targets.Count) (custom URL overrides suite). Range: $rangeSpec bytes; Timeout: $TimeoutSeconds s; Warn window: $WarnMinKB-$WarnMaxKB KB" -ForegroundColor Cyan + Write-Host "[INFO] Targets: $($Targets.Count) (custom URL overrides suite). Range: $rangeSpec bytes; Timeout: $($TimeoutSeconds)s" -ForegroundColor Cyan Write-Host "[INFO] Starting DPI TCP 16-20 checks (parallel: $MaxParallel)..." -ForegroundColor DarkGray $runspacePool = [runspacefactory]::CreateRunspacePool(1, $MaxParallel) $runspacePool.Open() + $payload = New-Object byte[] $RangeBytes + [System.Security.Cryptography.RandomNumberGenerator]::Create().GetBytes($payload) + + $payloadFile = New-TemporaryFile + [IO.File]::WriteAllBytes($payloadFile, $payload) + $scriptBlock = { - param($target, $tests, $rangeSpec, $TimeoutSeconds, $WarnMinKB, $WarnMaxKB) + param($payloadFile, $target, $tests, $rangeSpec, $TimeoutSeconds) $warned = $false $lines = @() foreach ($test in $tests) { $curlArgs = @( - "-L", "--range", $rangeSpec, "-m", $TimeoutSeconds, - "-w", "%{http_code} %{size_download}", + "-w", "%{http_code} %{size_upload} %{size_download} %{time_total}", "-o", "NUL", + "-X", "POST", + "--data-binary", "@$payloadFile", "-s" - ) + $test.Args + $target.Url + ) + $test.Args + @("https://$($target.Host)") - $output = & curl.exe @curlArgs 2>&1 + $output = $payload | curl.exe @curlArgs 2>&1 $exit = $LASTEXITCODE $text = ($output | Out-String).Trim() $code = "NA" - $sizeBytes = 0 + $upBytes = 0 + $downBytes = 0 + $time = -1 - if ($text -match '^(?\d{3})\s+(?\d+)$') { + if ($text -match '^(?\d{3})\s+(?\d+)\s+(?\d+)\s+(?