Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
POST /api/v1/recon/scan probes fleet ports from the server host, crawls owned HTTP targets, maps findings to spread lanes, and records optional oath ledger rows.
33 lines
832 B
Go
33 lines
832 B
Go
package recon
|
|
|
|
import (
|
|
"net"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
// dialPortFn overrides TCP probes in tests (nil = live dial from server host).
|
|
var dialPortFn func(host string, port int, timeout time.Duration) bool
|
|
|
|
// ScanPorts TCP-dials common fleet ports on host with timeout from server host.
|
|
func ScanPorts(host string) []PortResult {
|
|
out := make([]PortResult, 0, len(FleetPorts))
|
|
for _, port := range FleetPorts {
|
|
out = append(out, PortResult{Port: port, Open: dialPort(host, port, DefaultPortDialTimeout)})
|
|
}
|
|
return out
|
|
}
|
|
|
|
func dialPort(host string, port int, timeout time.Duration) bool {
|
|
if dialPortFn != nil {
|
|
return dialPortFn(host, port, timeout)
|
|
}
|
|
addr := net.JoinHostPort(host, strconv.Itoa(port))
|
|
conn, err := net.DialTimeout("tcp", addr, timeout)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
_ = conn.Close()
|
|
return true
|
|
}
|