Fix network map duplicate-device bug: drop nmap --send-ip (was causing MAC misattribution/stale ARP entries) and dedupe network_devices by MAC on every scan push so IP changes don't leave orphaned rows

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-18 19:52:34 -05:00
parent 141191bcdd
commit d97a345672
2 changed files with 6 additions and 1 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ fi
SUBNET="10.48.200.0/24"
TMPFILE=$(mktemp)
nmap -sn --send-ip "$SUBNET" 2>/dev/null > "$TMPFILE"
nmap -sn "$SUBNET" 2>/dev/null > "$TMPFILE"
if [ ! -s "$TMPFILE" ]; then
echo "$(date): nmap produced no output" >&2
+5
View File
@@ -35,6 +35,11 @@ foreach ($devices as $d) {
if (!$ip) continue;
$discoveredIPs[] = $ip;
if ($mac) {
// Device likely moved to a new IP (DHCP) — drop the stale row so it
// doesn't linger as an orphaned duplicate under the old address.
JarvisDB::execute('DELETE FROM network_devices WHERE mac=? AND ip<>?', [$mac, $ip]);
}
JarvisDB::execute(
'INSERT INTO network_devices (ip, mac, hostname, status, last_seen)
VALUES (?,?,?,?,NOW())