Add SpeedTest

This commit is contained in:
CristianD committed 2026-11-05 14:57:06 +00:00
commit d6f0bf73fc
1 file changed
+53
+53
View File
@@ -0,0 +1,53 @@
[CmdletBinding()]
param(
[int]$DownloadMB = 50,
[int]$UploadMB = 20
)
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Tls13
Write-Host "Initializing HTTPS speed test via Cloudflare CDN..." -ForegroundColor Cyan
# 1. Latency (TTFB probe)
$wc = New-Object System.Net.WebClient
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
try {
$null = $wc.DownloadString("https://speed.cloudflare.com/meta")
$latencyMs = [math]::Round($stopwatch.ElapsedMilliseconds)
Write-Host "Latency: $latencyMs ms" -ForegroundColor Yellow
} catch {
Write-Warning "Latency probe failed: $_"
}
# 2. Download Test
$downBytes = $DownloadMB * 1MB
Write-Host "Testing Download ($DownloadMB MB payload)..." -NoNewline
$stopwatch.Restart()
try {
$downData = $wc.DownloadData("https://speed.cloudflare.com/__down?bytes=$downBytes")
$stopwatch.Stop()
$downSec = $stopwatch.Elapsed.TotalSeconds
$downMbps = [math]::Round((($downData.Length * 8) / $downSec) / 1MB, 2)
Write-Host " Done." -ForegroundColor Green
Write-Host "Download: $downMbps Mbps" -ForegroundColor Green
} catch {
Write-Warning "`nDownload failed: $_"
}
# 3. Upload Test
$upBytes = New-Object byte[] ($UploadMB * 1MB)
(New-Object System.Random).NextBytes($upBytes)
Write-Host "Testing Upload ($UploadMB MB payload)..." -NoNewline
$stopwatch.Restart()
try {
$null = $wc.UploadData("https://speed.cloudflare.com/__up", "POST", $upBytes)
$stopwatch.Stop()
$upSec = $stopwatch.Elapsed.TotalSeconds
$upMbps = [math]::Round((($upBytes.Length * 8) / $upSec) / 1MB, 2)
Write-Host " Done." -ForegroundColor Green
Write-Host "Upload: $upMbps Mbps" -ForegroundColor Green
} catch {
Write-Warning "`nUpload failed: $_"
}
$wc.Dispose()