# NetTest for Windows - measures every connected network adapter (wired, Wi-Fi, ...) at once. # Latency, jitter and loss to the router and to the internet: all adapters at the same time. # Download / upload speed: one adapter after the other (they share the same line). # Results are shown here and then opened on the NetTest page (data travels in the URL #fragment, # which browsers never send to a server). Changes no settings, needs no admin rights. # # Run: irm https://nettest.likoras.com/nettest.ps1 | iex # or: powershell -ExecutionPolicy Bypass -File nettest.ps1 # Optional: $env:NETTEST_URL = 'http://host:port' to test against another server, # $env:NETTEST_NOBROWSER = '1' to skip opening the page. # (Non-ASCII text is written as \u escapes so the file reads the same under every code page.) & { $ErrorActionPreference = 'Continue' $Base = 'https://nettest.likoras.com' if ($env:NETTEST_URL) { $Base = $env:NETTEST_URL.TrimEnd('/') } $tr = $false try { $tr = ((Get-UICulture).Name -like 'tr*') -or ((Get-Culture).Name -like 'tr*') -or ((Get-TimeZone).Id -eq 'Turkey Standard Time') } catch {} function L([string]$t, [string]$e) { [regex]::Unescape($(if ($tr) { $t } else { $e })) } function Say([string]$s, [string]$c = 'Gray') { Write-Host $s -ForegroundColor $c } $PingCount = 30 $SpeedSeconds = 8 $Chunk = 16000000 # bytes per HTTP request (server maximum is 16 MiB) Say '' Say 'NetTest' 'Cyan' Say (L 'Kablo ve Wi-Fi ayn\u0131 anda \u00f6l\u00e7\u00fcl\u00fcyor' 'Measuring wired and Wi-Fi together') 'DarkGray' Say '' $curl = Join-Path $env:SystemRoot 'System32\curl.exe' if (-not (Test-Path $curl)) { Say (L 'Bu Windows s\u00fcr\u00fcm\u00fcnde curl.exe yok (Windows 10 1803 ve sonras\u0131 gerekir).' 'curl.exe is missing (Windows 10 1803 or later is required).') 'Red' return } # ---------- adapters ---------- $adapters = @() foreach ($c in (Get-NetIPConfiguration)) { $ad = $c.NetAdapter if (-not $ad -or $ad.Status -ne 'Up' -or -not $c.IPv4DefaultGateway -or -not $c.IPv4Address) { continue } $desc = "$($ad.InterfaceDescription)" $kind = 'other' if ("$($ad.PhysicalMediaType)" -match '802\.11' -or $desc -match 'Wi-?Fi|Wireless|WLAN|802\.11') { $kind = 'wifi' } elseif ($desc -match 'Mobile|Cellular|WWAN|LTE|5G') { $kind = 'mobile' } elseif ($ad.Virtual -or $desc -match 'Hyper-V|VPN|Virtual|TAP-|WireGuard|Tunnel') { $kind = 'other' } elseif ("$($ad.PhysicalMediaType)" -match '802\.3' -or "$($ad.MediaType)" -match '802\.3') { $kind = 'wired' } $adapters += [pscustomobject]@{ Name = $ad.Name; Desc = $desc; Kind = $kind IP = @($c.IPv4Address)[0].IPAddress GW = @($c.IPv4DefaultGateway)[0].NextHop Link = [math]::Round($ad.ReceiveLinkSpeed / 1e6) } } if ($adapters.Count -eq 0) { Say (L '\u0130nternete ba\u011fl\u0131 bir a\u011f ba\u011fda\u015ft\u0131r\u0131c\u0131s\u0131 bulunamad\u0131.' 'No network adapter with an internet route was found.') 'Red' return } $kindName = @{ wired = (L 'Kablo' 'Wired'); wifi = 'Wi-Fi'; mobile = (L 'Mobil' 'Mobile'); other = (L 'Di\u011fer' 'Other') } foreach ($a in $adapters) { Say (" {0,-7} {1} ({2}, {3})" -f $kindName[$a.Kind], $a.Name, $a.IP, $a.Desc) } if ($adapters.Count -eq 1) { Say '' Say (L 'Yaln\u0131zca bir ba\u011flant\u0131 a\u00e7\u0131k. \u0130kisini kar\u015f\u0131la\u015ft\u0131rmak i\u00e7in kabloyu tak\u0131n ve Wi-Fi\u2019yi de a\u00e7\u0131k tutun.' 'Only one connection is up. To compare, plug in the cable and keep Wi-Fi on as well.') 'Yellow' } # ---------- Wi-Fi details (netsh; may be empty if location access is off) ---------- $wlan = @{} try { $txt = (& netsh wlan show interfaces) -join "`n" foreach ($blk in ($txt -split "\n\s*\n")) { $name = if ($blk -match '(?m)^\s*\S[^:\r\n]*?\s*:\s*(.+?)\s*$') { $Matches[1] } else { $null } $info = @{} if ($blk -match '(?m)^\s*SSID\s*:\s*(.+?)\s*$') { $info.ssid = $Matches[1] } if ($blk -match '(?m):\s*(\d{1,3})\s*%\s*$') { $info.signal = [int]$Matches[1] } if ($blk -match '(\d(?:[.,]\d)?)\s*GHz') { $info.band = ($Matches[1] -replace ',', '.') + ' GHz' } if ($blk -match '(?m)^\s*(?:Channel|Kanal)\s*:\s*(\d+)') { $info.channel = $Matches[1] } if ($name -and $info.Count) { $wlan[$name] = $info } } } catch {} # ---------- helpers ---------- function Start-Ping([string]$src, [string]$dst, [int]$n) { $out = [IO.Path]::GetTempFileName() $p = Start-Process -FilePath (Join-Path $env:SystemRoot 'System32\ping.exe') -ArgumentList @('-S', $src, '-n', $n, '-w', '1000', $dst) ` -NoNewWindow -PassThru -RedirectStandardOutput $out [pscustomobject]@{ Proc = $p; Out = $out; N = $n } } function Read-Ping($job) { $job.Proc.WaitForExit() $lines = Get-Content $job.Out -ErrorAction SilentlyContinue Remove-Item $job.Out -ErrorAction SilentlyContinue $times = @() foreach ($l in $lines) { if ($l -notmatch 'TTL=') { continue } if ($l -match '<\s*1\s*ms') { $times += 0.5 } elseif ($l -match '=\s*(\d+)\s*ms') { $times += [double]$Matches[1] } } $med = $null; $jit = $null if ($times.Count) { $s = @($times | Sort-Object) $m = [math]::Floor($s.Count / 2) $med = if ($s.Count % 2) { $s[$m] } else { ($s[$m - 1] + $s[$m]) / 2 } } if ($times.Count -ge 2) { $sum = 0; for ($i = 1; $i -lt $times.Count; $i++) { $sum += [math]::Abs($times[$i] - $times[$i - 1]) } $jit = $sum / ($times.Count - 1) } [pscustomobject]@{ Median = $med; Jitter = $jit; Loss = 100 * ($job.N - $times.Count) / $job.N; Replies = $times.Count } } # Runs curl with the given URLs in parallel; returns Mbps measured by wall clock. function Invoke-Speed([string]$ip, [string[]]$urls, [string]$upFile) { $a = @('-s', '--interface', $ip, '--connect-timeout', '8', '--max-time', '40', '--parallel', '--parallel-max', '4', '-w', '%{size_download} %{size_upload} %{http_code}\n', '-H', 'Cache-Control: no-cache') if ($upFile) { $a += @('-X', 'POST', '-H', 'Content-Type: application/octet-stream', '--data-binary', "@$upFile") } foreach ($u in $urls) { $a += @($u, '-o', 'NUL') } $sw = [Diagnostics.Stopwatch]::StartNew() $lines = & $curl @a 2>$null $sw.Stop() $bytes = 0; $ok = 0 foreach ($l in @($lines)) { $p = "$l".Trim() -split '\s+' if ($p.Count -ge 3 -and $p[2] -eq '200') { $ok++; $bytes += [double]$(if ($upFile) { $p[1] } else { $p[0] }) } } if ($ok -eq 0 -or $sw.Elapsed.TotalSeconds -le 0) { return $null } [pscustomobject]@{ Mbps = $bytes * 8 / $sw.Elapsed.TotalSeconds / 1e6; Seconds = $sw.Elapsed.TotalSeconds } } function Urls([string]$path, [double]$total, [int]$each) { $n = [math]::Max(4, [math]::Ceiling($total / $each)) $n = [math]::Min($n, 200) $r = Get-Random $sep = if ($path.Contains('?')) { '&' } else { '?' } 1..$n | ForEach-Object { "$Base$path${sep}r=$r-$_" } } # ---------- 1) latency: every adapter at the same time ---------- Say '' Say ((L '1/2 Gecikme \u00f6l\u00e7\u00fcl\u00fcyor, t\u00fcm ba\u011flant\u0131larda ayn\u0131 anda (yakla\u015f\u0131k {0} sn)\u2026' '1/2 Measuring latency on all connections at once (about {0} s)...') -f $PingCount) 'Cyan' $jobs = @() foreach ($a in $adapters) { $jobs += [pscustomobject]@{ A = $a; GW = (Start-Ping $a.IP $a.GW $PingCount); NET = (Start-Ping $a.IP '1.1.1.1' $PingCount) } } $res = @{} foreach ($j in $jobs) { $res[$j.A.Name] = @{ gw = (Read-Ping $j.GW); net = (Read-Ping $j.NET) } } # ---------- 2) speed: one adapter after the other ---------- Say '' Say (L '2/2 H\u0131z \u00f6l\u00e7\u00fcl\u00fcyor, ba\u011flant\u0131lar s\u0131rayla\u2026' '2/2 Measuring speed, one connection at a time...') 'Cyan' $upFile = [IO.Path]::GetTempFileName() $rng = New-Object Security.Cryptography.RNGCryptoServiceProvider $buf = New-Object byte[] $Chunk $rng.GetBytes($buf) $rng.Dispose() function Write-UpFile([int]$size) { $fs = [IO.File]::Create($upFile); $fs.Write($buf, 0, $size); $fs.Close() } foreach ($a in $adapters) { Say (" {0} ({1})" -f $kindName[$a.Kind], $a.Name) $r = $res[$a.Name] # Download: short probe, then about $SpeedSeconds seconds of data. $probe = Invoke-Speed $a.IP @("$Base/api/down?bytes=2000000&r=$(Get-Random)") $null if (-not $probe) { Say (L ' Sunucuya bu ba\u011flant\u0131dan ula\u015f\u0131lamad\u0131, atland\u0131.' ' Server not reachable over this connection, skipped.') 'Yellow' continue } $total = [math]::Min([math]::Max($probe.Mbps * 1e6 / 8 * $SpeedSeconds, 8e6), 1.2e9) $pj = Start-Ping $a.IP '1.1.1.1' $SpeedSeconds $down = Invoke-Speed $a.IP (Urls "/api/down?bytes=$Chunk" $total $Chunk) $null $l1 = Read-Ping $pj if ($down) { Say ((L ' \u0130ndirme {0:N1} Mbps' ' Download {0:N1} Mbps') -f $down.Mbps) } # Upload: probe with 4 x 1 MB, then about $SpeedSeconds seconds of data. $size = 1000000 Write-UpFile $size $uprobe = Invoke-Speed $a.IP (Urls '/api/up' ($size * 4) $size) $upFile $up = $null; $l2 = $null if ($uprobe) { $total = [math]::Min([math]::Max($uprobe.Mbps * 1e6 / 8 * $SpeedSeconds, 4e6), 6e8) $size = [int][math]::Min([math]::Max($total / 8, 1e6), $Chunk) Write-UpFile $size $pj = Start-Ping $a.IP '1.1.1.1' $SpeedSeconds $up = Invoke-Speed $a.IP (Urls '/api/up' $total $size) $upFile $l2 = Read-Ping $pj } if ($up) { Say ((L ' Y\u00fckleme {0:N1} Mbps' ' Upload {0:N1} Mbps') -f $up.Mbps) } $loaded = @(@($l1.Median, $(if ($l2) { $l2.Median })) | Where-Object { $_ -ne $null }) $r.down = if ($down) { $down.Mbps } else { $null } $r.up = if ($up) { $up.Mbps } else { $null } $r.loaded = if ($loaded.Count) { ($loaded | Measure-Object -Average).Average } else { $null } } Remove-Item $upFile -ErrorAction SilentlyContinue # ---------- results ---------- $now = [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds() $out = @() $rows = @() $f = { param($v, $d) if ($v -eq $null) { '-' } else { "{0:N$d}" -f $v } } foreach ($a in $adapters) { $r = $res[$a.Name] $o = [ordered]@{ t = $now; kind = $a.Kind; adapter = $a.Name; link = $a.Link } if ($r.net.Median -ne $null) { $o.ping = [math]::Round($r.net.Median, 1) } if ($r.net.Jitter -ne $null) { $o.jitter = [math]::Round($r.net.Jitter, 1) } $o.loss = [math]::Round($r.net.Loss, 1) if ($r.gw.Median -ne $null) { $o.gw = [math]::Round($r.gw.Median, 1) } if ($r.gw.Jitter -ne $null) { $o.gwJitter = [math]::Round($r.gw.Jitter, 1) } $o.gwLoss = [math]::Round($r.gw.Loss, 1) if ($r.down -ne $null) { $o.down = [math]::Round($r.down, 2) } if ($r.up -ne $null) { $o.up = [math]::Round($r.up, 2) } if ($r.loaded -ne $null) { $o.loaded = [math]::Round($r.loaded, 1) } $w = $wlan[$a.Name] if ($a.Kind -eq 'wifi' -and -not $w -and $wlan.Count -eq 1) { $w = @($wlan.Values)[0] } if ($a.Kind -eq 'wifi' -and $w) { if ($w.ssid) { $o.ssid = $w.ssid } if ($w.signal -ne $null) { $o.signal = $w.signal } if ($w.band) { $o.band = $w.band + $(if ($w.channel) { " ch $($w.channel)" } else { '' }) } } $out += [pscustomobject]$o $rows += [pscustomobject][ordered]@{ (L 'Ba\u011flant\u0131' 'Connection') = "$($kindName[$a.Kind]) ($($a.Name))" (L '\u0130ndirme' 'Download') = (& $f $o.down 1) + ' Mbps' (L 'Y\u00fckleme' 'Upload') = (& $f $o.up 1) + ' Mbps' (L 'Gecikme' 'Latency') = (& $f $o.ping 0) + ' ms' 'Jitter' = (& $f $o.jitter 1) + ' ms' (L 'Y\u00fck alt\u0131nda' 'Loaded') = (& $f $o.loaded 0) + ' ms' (L 'Kay\u0131p' 'Loss') = (& $f $o.loss 0) + ' %' (L 'Modem' 'Router') = (& $f $o.gw 0) + ' ms / ' + (& $f $o.gwLoss 0) + ' %' } } Say '' $rows | Format-Table -AutoSize | Out-String -Width 200 | Write-Host foreach ($o in $out) { if ($o.signal -ne $null) { Say ((L ' Wi-Fi sinyali %{0}{1}' ' Wi-Fi signal {0}%{1}') -f $o.signal, $(if ($o.band) { ", $($o.band)" } else { '' })) } } $json = @{ v = 1; results = $out } | ConvertTo-Json -Compress -Depth 4 $b64 = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($json)).TrimEnd('=').Replace('+', '-').Replace('/', '_') $url = "$Base/#import=$b64" if ($env:NETTEST_NOBROWSER) { Say $url 'DarkGray' } else { Say (L 'Sonu\u00e7lar taray\u0131c\u0131da a\u00e7\u0131l\u0131yor\u2026' 'Opening the results in the browser...') 'Cyan' try { Start-Process $url } catch { Say $url } } Say '' }