MCPcopy Create free account
hub / github.com/SamNet-dev/snix / ProbeIPs

Function ProbeIPs

scanner/ip.go:49–78  ·  view source on GitHub ↗

ProbeIPs runs ProbeIP concurrently. Output order matches input.

(ctx context.Context, ips []string, port uint16, timeout time.Duration,
	concurrency int, onResult func(IPResult))

Source from the content-addressed store, hash-verified

47
48// ProbeIPs runs ProbeIP concurrently. Output order matches input.
49func ProbeIPs(ctx context.Context, ips []string, port uint16, timeout time.Duration,
50 concurrency int, onResult func(IPResult)) []IPResult {
51 if concurrency <= 0 {
52 concurrency = 16
53 }
54 sem := make(chan struct{}, concurrency)
55 out := make([]IPResult, len(ips))
56 var wg sync.WaitGroup
57 for i, s := range ips {
58 addr, err := netip.ParseAddr(s)
59 if err != nil {
60 out[i] = IPResult{Err: "parse: " + err.Error()}
61 continue
62 }
63 i, addr := i, addr
64 wg.Add(1)
65 sem <- struct{}{}
66 go func() {
67 defer wg.Done()
68 defer func() { <-sem }()
69 r := ProbeIP(ctx, addr, port, timeout)
70 out[i] = r
71 if onResult != nil {
72 onResult(r)
73 }
74 }()
75 }
76 wg.Wait()
77 return out
78}
79
80// RankIPs sorts reachable IPs by RTT ascending. Unreachable are dropped.
81func RankIPs(in []IPResult) []IPResult {

Callers 4

startIPMethod · 0.92
newScanIPCmdFunction · 0.92
newScanAllCmdFunction · 0.92
runWizardScansFunction · 0.92

Calls 2

ProbeIPFunction · 0.85
AddMethod · 0.80

Tested by

no test coverage detected