Windows: List applications binding a TCP Port
Windows Networking PowerShell
Have you ever needed to know what executable is binding to a specific port on windows?
Here is how, with a little bit of PowerShell:
1# buffer result in this list
2$list = @();
3
4# loop over all LISTEN ports
5foreach ($listener in Get-NetTCPConnection -State Listen | Sort-Object LocalPort) {
6
7 # get the owning process
8 $proc = Get-Process -Id (Get-NetTCPConnection -LocalPort $listener.LocalPort).OwningProcess
9
10 $ref = @{
11 'Port' = $listener.LocalPort
12 'Id' = $proc.Id
13 'ProcessName' = $proc.ProcessName
14 'Exe' = $proc.path # path to executable
15 'Type' = $proc.GetType()
16 }
17
18 # create object from hash for easier display inf Format-Table
19 $list += new-object psobject -Property $ref
20}
21
22# output
23$list | Format-Table
24