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

Function ProbeIP

scanner/ip.go:25–46  ·  view source on GitHub ↗

ProbeIP dials ip:port with cfg.ConnectTimeout and measures RTT. This is a plain TCP connect; no TLS. Returns Reachable=true only on successful three-way handshake.

(ctx context.Context, ip netip.Addr, port uint16, timeout time.Duration)

Source from the content-addressed store, hash-verified

23// plain TCP connect; no TLS. Returns Reachable=true only on successful
24// three-way handshake.
25func ProbeIP(ctx context.Context, ip netip.Addr, port uint16, timeout time.Duration) IPResult {
26 if port == 0 {
27 port = 443
28 }
29 if timeout <= 0 {
30 timeout = 2 * time.Second
31 }
32 r := IPResult{IP: ip, Port: port}
33 dialCtx, cancel := context.WithTimeout(ctx, timeout)
34 defer cancel()
35 start := time.Now()
36 conn, err := (&net.Dialer{}).DialContext(dialCtx, "tcp",
37 net.JoinHostPort(ip.String(), fmt.Sprintf("%d", port)))
38 r.RTT = time.Since(start)
39 if err != nil {
40 r.Err = err.Error()
41 return r
42 }
43 _ = conn.Close()
44 r.Reachable = true
45 return r
46}
47
48// ProbeIPs runs ProbeIP concurrently. Output order matches input.
49func ProbeIPs(ctx context.Context, ips []string, port uint16, timeout time.Duration,

Callers 1

ProbeIPsFunction · 0.85

Calls 2

StringMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected