# Router ping logger: ICMP round trip to the local router (default: Ethernet's gateway) every ~200 ms. # Runs alongside probe.ps1 to split local latency from internet latency (GL.iNet staff's own diagnostic). # Read-only. Stops on the same stop.flag as probe.ps1 (next to this script). Writes routerping.csv. param([string]$Target = '') $dir = Split-Path -Parent $MyInvocation.MyCommand.Path $out = Join-Path $dir 'routerping.csv' $stop = Join-Path $dir 'stop.flag' if (-not $Target) { $Target = (Get-NetRoute -InterfaceAlias 'Ethernet' -DestinationPrefix '0.0.0.0/0' | Sort-Object RouteMetric | Select-Object -First 1).NextHop } if (-not $Target) { throw 'no gateway found on Ethernet; pass -Target' } 'ts,target,gw_ms' | Out-File $out -Encoding ascii $ping = New-Object System.Net.NetworkInformation.Ping $sw = New-Object System.Diagnostics.Stopwatch while (-not (Test-Path $stop)) { $sw.Restart() $ms = -1 try { $p = $ping.Send($Target, 1000); if ($p.Status -eq 'Success') { $ms = $p.RoundtripTime } } catch {} "{0},{1},{2}" -f (Get-Date -Format 'HH:mm:ss.fff'), $Target, $ms | Out-File $out -Append -Encoding ascii $wait = 200 - [int]$sw.Elapsed.TotalMilliseconds if ($wait -gt 0) { Start-Sleep -Milliseconds $wait } }