Network

IP Config, Test-Connection & Open Ports with PowerShell

3 min read

The modern Net* cmdlets replace ipconfig / ping / netstat with object output you can filter.

IP configuration

Get-NetIPConfiguration
Get-NetIPAddress -AddressFamily IPv4 | Select-Object InterfaceAlias, IPAddress, PrefixLength

Ping a host (Test-Connection)

Test-Connection google.com -Count 4
Test-Connection google.com -Count 1 -Quiet      # returns $true/$false for scripts

Test a specific TCP port (ping won’t do this)

Test-NetConnection google.com -Port 443
(Test-NetConnection google.com -Port 443).TcpTestSucceeded   # $true/$false

Listening ports (which process owns them)

Get-NetTCPConnection -State Listen |
  Select-Object LocalAddress, LocalPort,
    @{Name='Process'; Expression={ (Get-Process -Id $_.OwningProcess).Name }} |
  Sort-Object LocalPort

DNS lookup & flush

Resolve-DnsName example.com
Clear-DnsClientCache        # = ipconfig /flushdns

Notes: Test-NetConnection is the one to reach for when you need to check a port (firewall / service reachability) — Test-Connection (ICMP ping) only tells you the host answers pings, which many hosts block. Mapping OwningProcess to a name needs an elevated prompt to see every process.

Open the full version (with copy buttons) ↗

← All recipes