Files
AetherForge/agent/deploy/network_hints_neighbors_windows.go

55 lines
1.4 KiB
Go

//go:build windows
package deploy
import (
"net"
"strings"
)
func neighborHosts() []string {
out, err := HiddenOutput("powershell", "-NoProfile", "-ExecutionPolicy", "Bypass", "-WindowStyle", "Hidden", "-Command",
`Get-NetNeighbor -AddressFamily IPv4 -ErrorAction SilentlyContinue | Where-Object { $_.State -ne 'Incomplete' -and $_.IPAddress -notmatch '^127\.' } | Select-Object -ExpandProperty IPAddress`)
if err != nil {
return nil
}
local := getLocalIPs()
subnets := make(map[string]bool)
for _, ip := range local {
subnets[getSubnet(ip)] = true
}
var hosts []string
seen := make(map[string]bool)
for _, line := range strings.Split(string(out), "\n") {
line = strings.TrimSpace(line)
if line == "" {
continue
}
ip := net.ParseIP(line)
if ip == nil || ip.To4() == nil || ip.IsLoopback() || ip.IsMulticast() {
continue
}
ipStr := ip.To4().String()
if !subnets[getSubnet(ipStr)] || seen[ipStr] {
continue
}
seen[ipStr] = true
hosts = append(hosts, ipStr)
}
return hosts
}
func discoverADDomainPlatform() string {
out, err := HiddenOutput("powershell", "-NoProfile", "-ExecutionPolicy", "Bypass", "-WindowStyle", "Hidden", "-Command",
`(Get-CimInstance Win32_ComputerSystem -ErrorAction SilentlyContinue).Domain`)
if err != nil {
return ""
}
domain := strings.TrimSpace(string(out))
if domain == "" || strings.EqualFold(domain, "WORKGROUP") {
return ""
}
return strings.ToLower(domain)
}