Currently, we use some logic in PowerShell to do a netstat -ano
to get all TCP and UDP results and filter out results that we don't need to see then export it into a CSV. We want the results to only include the LISTENING and (blank) and non-loopback IP's.
One example would be netstat -ano | Where-Object{$_ -notlike '*127.?.?.?*' -and $_ -notmatch '\[::1]' -and $_ -notmatch 'TIME_WAIT' -and $_ -notmatch 'CLOSE*' -and $_ -notmatch 'ESTABLISHED' -and $_ -notmatch 'SYN_*' -and $_ -notmatch 'FIN_*'}
.
However, we don't want to miss the other options that can come through at other times if we happen to be running our script at the same time. One I just found is LAST_ACK and I don't know what other options there are that our logic doesn't include already.
Is there a way to flip that logic instead of filtering out all of those matches, can we only include matches that are either (blank) or LISTENING or non-loopback IP's? If not, I can add more to that logic, but just wanted to see the thoughts of some of the experts.
ANSWER: I found all the states here and just updated it to include all of those.
Get-NetTCPConnection
yet? [grin]netstat
into an array of PoSh objects that you can easily filter as needed. hopefully that gives you what you need. [grin]