Created
November 29, 2018 13:10
-
-
Save raspi/8c6b416b7d5f698f69e51f6cf88205b3 to your computer and use it in GitHub Desktop.
List established IPs and ports with DNS resolved names and program names
This file contains hidden or 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
# List established IPs and ports with DNS resolved names and program names | |
$nfo = @() | |
ForEach ($c in Get-NetTCPConnection -State Established) { | |
if ($c.LocalAddress -eq $c.RemoteAddress) { | |
# skip same IP's | |
Continue | |
} | |
$prog = (Get-Process -Id $c.OwningProcess) | |
try { | |
# Try to resolve IP to host name | |
$r = [System.Net.Dns]::GetHostEntry($c.RemoteAddress).HostName | |
} catch { | |
$r = "-" | |
} | |
$nfo += New-Object PSObject -Property @{ | |
LocalAddress = $c.LocalAddress | |
LocalPort = $c.LocalPort | |
RemoteHost = $r | |
RemoteAddress = $c.RemoteAddress | |
RemotePort = $c.RemotePort | |
ProcName = $prog.Name | |
ProcPath = $prog.Path | |
ProcProduct = $prog.Product | |
PID = $c.OwningProcess | |
} | |
} | |
$nfo | Select -ErrorAction SilentlyContinue RemoteAddress, RemotePort, RemoteHost, LocalAddress, LocalPort, ProcProduct, PID, ProcPath, * | Sort PID,RemoteAddress,RemotePort | Format-Table |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment