51 lines
954 B
Go
51 lines
954 B
Go
//go:build !windows
|
|
|
|
package deploy
|
|
|
|
import (
|
|
"bufio"
|
|
"net"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
func neighborHosts() []string {
|
|
out, err := exec.Command("ip", "-4", "neighbor", "show").Output()
|
|
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)
|
|
scanner := bufio.NewScanner(strings.NewReader(string(out)))
|
|
for scanner.Scan() {
|
|
fields := strings.Fields(scanner.Text())
|
|
if len(fields) < 1 {
|
|
continue
|
|
}
|
|
ip := net.ParseIP(fields[0])
|
|
if ip == nil || ip.To4() == nil {
|
|
continue
|
|
}
|
|
if len(fields) >= 5 && strings.EqualFold(fields[len(fields)-1], "FAILED") {
|
|
continue
|
|
}
|
|
ipStr := ip.To4().String()
|
|
if !subnets[getSubnet(ipStr)] || seen[ipStr] {
|
|
continue
|
|
}
|
|
seen[ipStr] = true
|
|
hosts = append(hosts, ipStr)
|
|
}
|
|
return hosts
|
|
}
|
|
|
|
func discoverADDomainPlatform() string {
|
|
return ""
|
|
}
|