59 lines
2.2 KiB
PowerShell
59 lines
2.2 KiB
PowerShell
param(
|
|
[ValidateSet("http","socks")]
|
|
[string]$Mode = "http",
|
|
|
|
[int]$SizeMB = 50
|
|
)
|
|
|
|
# Build proxy value and target URL
|
|
$proxy = if ($Mode -eq "http") { "http://127.0.0.1:8080" } else { "socks5h://127.0.0.1:1080" }
|
|
$envVar = if ($Mode -eq "http") { "HTTPS_PROXY" } else { "ALL_PROXY" }
|
|
$bytes = [int64]$SizeMB * 1MB
|
|
$testUrl = "https://speed.cloudflare.com/__down?bytes=$bytes"
|
|
|
|
Write-Host "Mode: $Mode Proxy: $proxy Size: $SizeMB MB" -ForegroundColor Cyan
|
|
|
|
# Set proxy env only for this process
|
|
[System.Environment]::SetEnvironmentVariable($envVar, $proxy, 'Process')
|
|
|
|
function Test-Health {
|
|
try {
|
|
Write-Host "Checking server health via proxy..." -ForegroundColor Yellow
|
|
$health = & curl.exe -I https://molecular.eu.org/_health 2>&1
|
|
$line = ($health | Select-String -Pattern "HTTP/").ToString()
|
|
Write-Host $line -ForegroundColor Green
|
|
} catch {
|
|
Write-Host "Health check failed: $_" -ForegroundColor Red
|
|
}
|
|
}
|
|
|
|
function Test-Download {
|
|
param([string]$Url)
|
|
Write-Host "Running download test: $Url" -ForegroundColor Yellow
|
|
$result = & curl.exe -sS -o NUL -w "time_namelookup=%{time_namelookup} time_connect=%{time_connect} time_starttransfer=%{time_starttransfer} time_total=%{time_total} speed_download=%{speed_download}\n" $Url
|
|
if (-not $result) { Write-Host "curl produced no output." -ForegroundColor Red; return }
|
|
|
|
$kv = @{}
|
|
foreach ($pair in $result.Trim().Split(' ')) {
|
|
if ($pair -match "=") {
|
|
$k,$v = $pair.Split('='); $kv[$k] = [double]$v
|
|
}
|
|
}
|
|
$mbps = [math]::Round(($kv['speed_download'] * 8.0) / 1e6, 2)
|
|
Write-Host ("Latency(connect): {0} s | TTFB: {1} s | Total: {2} s | Throughput: {3} Mbps" -f `
|
|
$kv['time_connect'], $kv['time_starttransfer'], $kv['time_total'], $mbps) -ForegroundColor Green
|
|
}
|
|
|
|
Test-Health
|
|
Test-Download -Url $testUrl
|
|
|
|
# Optional: run a smaller warm-up and a larger sustained test
|
|
if ($SizeMB -lt 20) {
|
|
Test-Download -Url "https://speed.cloudflare.com/__down?bytes=20000000" # 20MB
|
|
}
|
|
if ($SizeMB -lt 100) {
|
|
Test-Download -Url "https://speed.cloudflare.com/__down?bytes=100000000" # 100MB
|
|
}
|
|
|
|
Write-Host "Done." -ForegroundColor Cyan
|