17 lines
1.0 KiB
PowerShell
17 lines
1.0 KiB
PowerShell
function Get-SamsaraNetwork {
|
|
param($Result)
|
|
$processes = @{}
|
|
Invoke-SamsaraRead $Result 'Process names' {
|
|
Get-Process -ErrorAction Stop | ForEach-Object { $processes[[int]$_.Id] = [string]$_.ProcessName }
|
|
}
|
|
Invoke-SamsaraRead $Result 'TCP connections' {
|
|
$Result.data = @(Get-NetTCPConnection -ErrorAction Stop | ForEach-Object {
|
|
$processName = if ($processes.ContainsKey([int]$_.OwningProcess)) { $processes[[int]$_.OwningProcess] } else { 'Unavailable or process exited' }
|
|
[pscustomobject]@{ state = [string]$_.State; local_address = [string]$_.LocalAddress; local_port = [int]$_.LocalPort
|
|
remote_address = [string]$_.RemoteAddress; remote_port = [int]$_.RemotePort
|
|
pid = [int]$_.OwningProcess; process = $processName; direction = 'Unknown' }
|
|
})
|
|
}
|
|
$Result.limitations += 'Point-in-time TCP only. Connection direction, historical activity, UDP and other network compartments are unverified. Process names may race process exit or be hidden.'
|
|
}
|