Network Diagnostics
Diagnose Windows network connectivity — test connections, resolve DNS, trace routes, check open ports, and inspect network interfaces — all from PowerShell.
When to Use
- User reports internet or network connectivity issues
- User wants to test if a host or port is reachable
- User asks for their IP address, gateway, or DNS settings
- User wants to run a traceroute or DNS lookup
- User needs to check what processes are using which ports
How to Use
Test connectivity to a host
powershellTest-Connection -ComputerName "8.8.8.8" -Count 4 Test-Connection -ComputerName "google.com" -Count 4 | Select-Object Address, Latency, Status
Test TCP port connectivity
powershellTest-NetConnection -ComputerName "github.com" -Port 443 Test-NetConnection -ComputerName "smtp.gmail.com" -Port 587
Get network interface info
powershellGet-NetIPAddress | Where-Object AddressFamily -eq 'IPv4' | Select-Object InterfaceAlias, IPAddress, PrefixLength | Where-Object IPAddress -notmatch '^169|^127'
Get default gateway
powershellGet-NetRoute -DestinationPrefix "0.0.0.0/0" | Select-Object InterfaceAlias, NextHop, RouteMetric
DNS lookup
powershellResolve-DnsName "google.com" Resolve-DnsName "google.com" -Type MX # Mail records Resolve-DnsName "google.com" -Type TXT # TXT records
Flush DNS cache
powershellClear-DnsClientCache
Traceroute
powershellTest-NetConnection -ComputerName "8.8.8.8" -TraceRoute
View active TCP connections (netstat equivalent)
powershellGet-NetTCPConnection -State Established | Select-Object LocalAddress, LocalPort, RemoteAddress, RemotePort, State | Sort-Object LocalPort
Find process using a port
powershell$port = 3000 $conn = Get-NetTCPConnection -LocalPort $port -ErrorAction SilentlyContinue if ($conn) { $proc = Get-Process -Id $conn.OwningProcess -ErrorAction SilentlyContinue Write-Host "Port $port is used by: $($proc.Name) (PID $($conn.OwningProcess))" } else { Write-Host "Port $port is free" }
Check Wi-Fi signal strength
powershellnetsh wlan show interfaces | Select-String "Signal|SSID|State"
Reset network stack
powershell# Requires elevated session # netsh int ip reset # netsh winsock reset Write-Host "To reset network stack, run the above commands in an elevated PowerShell session"
Examples
"Can I reach GitHub from this machine?"
→ Test-NetConnection -ComputerName "github.com" -Port 443 — checks both DNS resolution and TCP handshake.
"What's my local IP and gateway?"
→ Get-NetIPAddress for IP + Get-NetRoute -DestinationPrefix "0.0.0.0/0" for gateway.
"Which process is listening on port 8080?"
→ Find the OwningProcess from Get-NetTCPConnection and cross-reference with Get-Process.
Cautions
Test-NetConnection -TraceRoutecan be slow (30+ seconds) for distant hosts — warn the userGet-NetTCPConnectionshows socket-level connections; some processes use UDP (Get-NetUDPEndpoint)- Network reset commands require an elevated session and will briefly drop all connections
- DNS changes may take time to propagate;
Clear-DnsClientCacheonly clears the local resolver cache


