9050 DataFox Terminal » active_tcp_connection.ps1
| 1 |
[CmdletBinding()] |
|---|---|
| 2 |
param( |
| 3 |
[Parameter(Mandatory = $true, Position = 0)] |
| 4 |
[ValidateRange(1, 65535)] |
| 5 |
[int]$Port |
| 6 |
)
|
| 7 |
cls
|
| 8 |
Get-NetTCPConnection | |
| 9 |
Where-Object { $_.LocalPort -eq $Port -or $_.RemotePort -eq $Port } | |
| 10 |
Select-Object LocalAddress, |
| 11 |
LocalPort, |
| 12 |
RemoteAddress, |
| 13 |
RemotePort, |
| 14 |
State, |
| 15 |
@{Name='PID'; Expression={$_.OwningProcess}}, |
| 16 |
@{Name='ProcessName'; Expression={(Get-Process -Id $_.OwningProcess -ErrorAction SilentlyContinue).ProcessName}}, |
| 17 |
@{Name='Path'; Expression={(Get-Process -Id $_.OwningProcess -ErrorAction SilentlyContinue).Path}} | |
| 18 |
Sort-Object RemoteAddress | |
| 19 |
Format-Table -AutoSize |