16 lines
827 B
PowerShell
16 lines
827 B
PowerShell
# Non-perturbing socket-table probe: which SOTS process holds which UDP port, right now.
|
|
$ts = Get-Date -Format "HH:mm:ss.fff"
|
|
$procs = @{}
|
|
Get-Process -Name 'Sword of the Stars' -ErrorAction SilentlyContinue | ForEach-Object { $procs[$_.Id] = $_.Id }
|
|
$rows = @()
|
|
foreach ($e in (Get-NetUDPEndpoint -ErrorAction SilentlyContinue)) {
|
|
if ($procs.ContainsKey([int]$e.OwningProcess)) {
|
|
$rows += "$ts UDP pid=$($e.OwningProcess) $($e.LocalAddress):$($e.LocalPort)"
|
|
}
|
|
}
|
|
foreach ($e in (Get-NetTCPConnection -ErrorAction SilentlyContinue)) {
|
|
if ($procs.ContainsKey([int]$e.OwningProcess)) {
|
|
$rows += "$ts TCP pid=$($e.OwningProcess) $($e.LocalAddress):$($e.LocalPort) -> $($e.RemoteAddress):$($e.RemotePort) $($e.State)"
|
|
}
|
|
}
|
|
if ($rows.Count -eq 0) { "$ts (no SOTS process / no sockets)" } else { $rows | Sort-Object }
|