Skip to content

Instantly share code, notes, and snippets.

@kissge
Last active April 9, 2022 14:21
Show Gist options
  • Save kissge/6878da52bf2359adb99cf6de239892bf to your computer and use it in GitHub Desktop.
Save kissge/6878da52bf2359adb99cf6de239892bf to your computer and use it in GitHub Desktop.
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
{
# Relaunch as an elevated process:
Start-Process powershell.exe "-File",('"{0}"' -f $MyInvocation.MyCommand.Path) -Verb RunAs
exit
}
$set = @{}
while ($true) {
(netstat -bano -p tcp | Select -skip 4) -join "`n" -split "(?= [TU][CD]P\s+(?:\d+\.|\[\w*:\w*:))" |
% {
$key = $_.trim() -replace "`n", ' ' -replace '\*\:\*', '*:*,' -replace '\s{2,}', ','
if (-Not $set.ContainsKey($key)) {
echo $key
$set[$key] = $true
}
}
if([console]::KeyAvailable) {
break
}
}
$TempFile = New-TemporaryFile | Rename-Item -NewName { $_.Name -replace '.tmp', '-legalscape-debug.txt' } -Passthru
echo $set.keys > $TempFile
Start-Process -FilePath C:\Windows\explorer.exe -ArgumentList "/select, ""$TempFile"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment