Skip to content

Commit 13ca550

Browse files
authored
Refactor Test-NetworkLatency function for clarity (#17)
1 parent e325187 commit 13ca550

1 file changed

Lines changed: 8 additions & 12 deletions

File tree

SystemTester.ps1

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -575,36 +575,33 @@ function Test-NetworkSpeed {
575575

576576
function Test-NetworkLatency {
577577
Write-Host "`n=== Network Latency (Test-NetConnection & PsPing) ===" -ForegroundColor Green
578-
579578
$targetHost = "8.8.8.8"
580-
$lines = @("Target: $($targetHost):$targetPort")
579+
$lines = @("Target: $targetHost")
581580
$status = "SUCCESS"
582-
583-
# Built-in Test-NetConnection results
581+
582+
# Built-in Test-NetConnection results (ICMP only)
584583
try {
585-
$tnc = Test-NetConnection -ComputerName $targetHost -Port $targetPort -InformationLevel Detailed
584+
$tnc = Test-NetConnection -ComputerName $targetHost -InformationLevel Detailed
586585
if ($tnc) {
587586
$lines += "Test-NetConnection:"
588587
$lines += " Ping Succeeded: $($tnc.PingSucceeded)"
589588
if ($tnc.PingReplyDetails) {
590589
$lines += " Ping RTT: $($tnc.PingReplyDetails.RoundtripTime) ms"
591590
}
592-
$lines += " TCP Succeeded: $($tnc.TcpTestSucceeded)"
593591
}
594592
} catch {
595593
$status = "FAILED"
596594
$lines += "Test-NetConnection: Failed - $($_.Exception.Message)"
597595
}
598-
599-
# Sysinternals PsPing results
596+
597+
# Sysinternals PsPing results (ICMP only)
600598
try {
601599
$pspingPath = Join-Path $SysinternalsPath "psping.exe"
602600
if (Test-Path $pspingPath) {
603-
$pspingArgs = @("-accepteula", "-n", "5", "{0}:{1}" -f $targetHost, $targetPort)
601+
$pspingArgs = @("-accepteula", "-n", "5", $targetHost)
604602
Write-Host "Running PsPing latency test..." -ForegroundColor Yellow
605603
$pspingOutput = & $pspingPath $pspingArgs 2>&1 | Out-String
606604
$lines += "PsPing Summary:"
607-
608605
$average = $null
609606
$minimum = $null
610607
$maximum = $null
@@ -615,7 +612,6 @@ function Test-NetworkLatency {
615612
$average = [double]$matches[3]
616613
}
617614
}
618-
619615
if ($null -ne $average) {
620616
$lines += " Min: $minimum ms"
621617
$lines += " Max: $maximum ms"
@@ -630,7 +626,7 @@ function Test-NetworkLatency {
630626
$status = "FAILED"
631627
$lines += "PsPing Summary: Failed - $($_.Exception.Message)"
632628
}
633-
629+
634630
$script:TestResults += @{
635631
Tool="Network-Latency"; Description="Connectivity latency tests"
636632
Status=$status; Output=($lines -join "`n"); Duration=0

0 commit comments

Comments
 (0)