4d6c2fd878
Fast (~1-3s) endpoint that gathers network info about a device before full stream discovery. Runs ping first, then parallel probes. Features: - Ping with ICMP + TCP fallback (works without root) - Reverse DNS hostname lookup - ARP table MAC address + OUI vendor identification (2403 entries, 51 camera vendors) - mDNS HomeKit detection (camera/doorbell, paired status) - Extensible Prober interface for adding new probe types - 3-second overall timeout, parallel execution Response includes "type" field: - "unreachable" - device not responding - "standard" - normal IP camera (RTSP/HTTP/ONVIF flow) - "homekit" - Apple HomeKit camera (PIN pairing flow)
37 lines
829 B
Go
37 lines
829 B
Go
package discovery
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"strings"
|
|
|
|
"github.com/eduard256/Strix/internal/models"
|
|
)
|
|
|
|
// DNSProber performs reverse DNS lookup to find the hostname of a device.
|
|
type DNSProber struct{}
|
|
|
|
func (p *DNSProber) Name() string { return "dns" }
|
|
|
|
// Probe performs a reverse DNS lookup on the given IP.
|
|
// Returns nil if no hostname is found (not an error).
|
|
func (p *DNSProber) Probe(ctx context.Context, ip string) (any, error) {
|
|
resolver := net.DefaultResolver
|
|
|
|
names, err := resolver.LookupAddr(ctx, ip)
|
|
if err != nil || len(names) == 0 {
|
|
return nil, nil // No hostname found is not an error
|
|
}
|
|
|
|
// LookupAddr returns FQDNs with trailing dot, remove it
|
|
hostname := strings.TrimSuffix(names[0], ".")
|
|
|
|
if hostname == "" {
|
|
return nil, nil
|
|
}
|
|
|
|
return &models.DNSProbeResult{
|
|
Hostname: hostname,
|
|
}, nil
|
|
}
|