Files
2026-11-09 13:40:48 +00:00

54 lines
2.0 KiB
PowerShell

[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
$wc = New-Object System.Net.WebClient
# IP Address Detection
try {
$internalIP = (Get-NetIPAddress -AddressFamily IPv4 -InterfaceAlias * | Where-Object { $_.IPAddress -notlike "127.*" -and $_.IPAddress -notlike "169.254.*" } | Select-Object -First 1).IPAddress
$externalIP = ($wc.DownloadString("https://api.ipify.org")).Trim()
Write-Host "Internal IP: $internalIP" -ForegroundColor Yellow
Write-Host "External IP: $externalIP" -ForegroundColor Yellow
} catch {
Write-Warning "Failed to resolve IP addresses: $_"
}
# 1. Download Test
$downBytes = $DownloadMB * 1MB
Write-Host "Testing Download ($DownloadMB MB payload)..." -NoNewline
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
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: $_"
}
# 2. 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()