Skip to content

Instantly share code, notes, and snippets.

@chadmando
Created March 19, 2024 15:04
Show Gist options
  • Save chadmando/cab12c76c210aeaeeb12816632930960 to your computer and use it in GitHub Desktop.
Save chadmando/cab12c76c210aeaeeb12816632930960 to your computer and use it in GitHub Desktop.
ns command written in powershell to include lifetime of established connections - TCP version
# Full credit for this goes to a SANS ICS diary by Rob Vandenbrink
# https://isc.sans.edu/diary/30532?n
$now = get-date
Get-NetTCPConnection |
select-object LocalAddress,LocalPort,RemoteAddress,RemotePort,State,@{Name="LifetimeSec";Expression={($now-$_.CreationTime).seconds}},OwningProcess, @{Name="Process";Expression={(Get-Process -Id $_.OwningProcess).ProcessName}} |
sort-object -property LifetimeSec |
select-object -last 10 |
ft -auto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment