How do I identify the Windows process using a local TCP port?
Use Get-NetTCPConnection to find the local listener and its owning process ID. This is useful when an SSH tunnel cannot bind its chosen local port. Identify the application before deciding whether any process should be stopped.
Instructions
1. Inspect the specific local port
Port 8080 is an example for a local tunnel or test application.
Get-NetTCPConnection -State Listen -LocalPort 8080 | Select-Object LocalAddress, LocalPort, OwningProcessCheck whether the listener binds to loopback, a particular interface or every interface.
2. Look up the reported process ID
Use the actual PID returned by the previous command, not a value copied from another computer.
Get-Process -Id 1234 | Select-Object Id, ProcessName, PathReplace 1234 with the observed PID. Some process details require administrative access.
3. Resolve the conflict narrowly
For an SSH tunnel, select another unused local port if permitted. If the existing application should be stopped, use its normal authorised shutdown mechanism. Do not terminate an unknown process merely because it occupies the desired port.
Check the result
- The process identity corresponds to the observed port listener.
- The intended tunnel or application can bind its approved local port.
Troubleshooting
- No listener is found
- The conflict may be transient, use another address family, or involve a reserved port range.
- The process details are inaccessible
- Use an authorised elevated diagnostic session if necessary; do not change permissions on system processes.
Official references
Use the documentation for your installed version when a flag, service name or platform feature differs.
