Last active
March 18, 2019 20:56
-
-
Save tylerapplebaum/f6577e0fa53f095f1ad64ca7e684db5a to your computer and use it in GitHub Desktop.
Just like "netstat -f | findstr ESTABLISHED" but in PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Resolve-EstablishedConnections { | |
$EstConnections = Get-NetTCPConnection -State Established | |
$ConnectionArr = New-Object System.Collections.ArrayList #Initialize the ArrayList | |
$Counter = 1 | |
ForEach ($Connection in $EstConnections) { | |
Write-Progress -Activity "Resolving PTR Record" -Status "Looking up $($Connection.RemoteAddress)" -PercentComplete ($Counter / $($EstConnections.Length)*100) | |
$ConnectionObj = [PSCustomObject][Ordered] @{ | |
LocalAddress = $Connection.LocalAddress | |
LocalPort = $Connection.LocalPort | |
RemoteAddress = $Connection.RemoteAddress | |
RemoteName = Resolve-DnsName -Name $Connection.RemoteAddress -ErrorAction SilentlyContinue | Select-Object -ExpandProperty NameHost | |
RemotePort = $Connection.RemotePort | |
State = $Connection.State | |
} | |
$ConnectionArr.Add($ConnectionObj) | Out-Null #Add the object to the array | |
$Counter++ | |
} #End ForEach | |
$ConnectionArr | Out-GridView -Title Resolve-EstablishedConnections | |
Return $ConnectionArr | |
} #End Resolve-EstablishedConnections | |
. Resolve-EstablishedConnections |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: