Skip to content

Instantly share code, notes, and snippets.

@a5ync
Created December 12, 2019 17:46
Show Gist options
  • Select an option

  • Save a5ync/ee6c2ba8e3decc107cf6edd9eaebaddb to your computer and use it in GitHub Desktop.

Select an option

Save a5ync/ee6c2ba8e3decc107cf6edd9eaebaddb to your computer and use it in GitHub Desktop.
Logging netstat from powershell
$ipTracking="10.200.0.109"
while(1)
{
$date=get-date -format "yyyy/MM/dd HH:mm:ss"
$connections =(get-nettcpconnection -remoteaddress $ipTracking `
-ErrorAction SilentlyContinue `
| select-object -Property LocalAddress,LocalPort,RemoteAddress,RemotePort,State, `
@{name='Process';expression={(Get-Process -Id $_.OwningProcess).Name}},CreationTime `
| format-table -Autosize) `
| out-string
Write-Host $date $connections
Add-content -Path c:\repos\connections.log -Value "$date $connections"
Start-Sleep -Seconds 10
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment