diff --git a/internal/probe/probe.go b/internal/probe/probe.go index 057ce9e..5d2175c 100644 --- a/internal/probe/probe.go +++ b/internal/probe/probe.go @@ -21,8 +21,6 @@ const probeTimeout = 100 * time.Millisecond var log zerolog.Logger var db *sql.DB var ports []int -var hasICMP bool - var detectors []func(*probe.Response) string func Init() { @@ -35,14 +33,6 @@ func Init() { } ports = loadPorts() - hasICMP = probe.CanICMP() - - if hasICMP { - log.Info().Msg("[probe] ICMP available") - } else { - log.Info().Msg("[probe] ICMP not available, using port scan only") - } - // HomeKit detector detectors = append(detectors, func(r *probe.Response) string { if r.Probes.MDNS != nil && !r.Probes.MDNS.Paired { @@ -123,26 +113,10 @@ func runProbe(parent context.Context, ip string) *probe.Response { mu.Unlock() }) - if hasICMP { - run(func() { - r, _ := probe.Ping(ctx, ip) - mu.Lock() - resp.Probes.Ping = r - mu.Unlock() - }) - } - wg.Wait() // determine reachable resp.Reachable = resp.Probes.Ports != nil && len(resp.Probes.Ports.Open) > 0 - if !resp.Reachable && resp.Probes.Ping != nil { - resp.Reachable = true - } - - if resp.Reachable && resp.Probes.Ping != nil { - resp.LatencyMs = resp.Probes.Ping.LatencyMs - } // determine type resp.Type = "standard" @@ -184,10 +158,11 @@ func loadPorts() []int { return defaultPorts() } + result = append(result, 51826) log.Info().Int("count", len(result)).Msg("[probe] loaded ports from db") return result } func defaultPorts() []int { - return []int{554, 80, 8080, 443, 8554, 5544, 10554, 1935, 81, 88, 8090, 8001, 8081, 7070, 7447, 34567} + return []int{554, 80, 8080, 443, 8554, 5544, 10554, 1935, 81, 88, 8090, 8001, 8081, 7070, 7447, 34567, 51826} } diff --git a/pkg/probe/models.go b/pkg/probe/models.go index 04abfa7..a67e6df 100644 --- a/pkg/probe/models.go +++ b/pkg/probe/models.go @@ -3,14 +3,12 @@ package probe type Response struct { IP string `json:"ip"` Reachable bool `json:"reachable"` - LatencyMs float64 `json:"latency_ms,omitempty"` - Type string `json:"type"` // "unreachable", "standard", "homekit" + Type string `json:"type"` // "unreachable", "standard", "homekit" Error string `json:"error,omitempty"` Probes Probes `json:"probes"` } type Probes struct { - Ping *PingResult `json:"ping"` Ports *PortsResult `json:"ports"` DNS *DNSResult `json:"dns"` ARP *ARPResult `json:"arp"` @@ -18,10 +16,6 @@ type Probes struct { HTTP *HTTPResult `json:"http"` } -type PingResult struct { - LatencyMs float64 `json:"latency_ms"` -} - type PortsResult struct { Open []int `json:"open"` } diff --git a/pkg/probe/ping.go b/pkg/probe/ping.go deleted file mode 100644 index 459067b..0000000 --- a/pkg/probe/ping.go +++ /dev/null @@ -1,39 +0,0 @@ -package probe - -import ( - "context" - "net" - "time" -) - -func CanICMP() bool { - conn, err := net.DialTimeout("ip4:icmp", "127.0.0.1", 100*time.Millisecond) - if err != nil { - return false - } - conn.Close() - return true -} - -func Ping(ctx context.Context, ip string) (*PingResult, error) { - deadline, ok := ctx.Deadline() - if !ok { - deadline = time.Now().Add(100 * time.Millisecond) - } - - timeout := time.Until(deadline) - if timeout <= 0 { - return nil, context.DeadlineExceeded - } - - start := time.Now() - conn, err := net.DialTimeout("ip4:icmp", ip, timeout) - if err != nil { - return nil, err - } - conn.Close() - - return &PingResult{ - LatencyMs: float64(time.Since(start).Microseconds()) / 1000.0, - }, nil -}