diff --git a/api/endpoints/netscan.php b/api/endpoints/netscan.php index fa47cbd..cc92221 100644 --- a/api/endpoints/netscan.php +++ b/api/endpoints/netscan.php @@ -29,18 +29,21 @@ foreach ($devices as $d) { $mac = trim($d['mac'] ?? ''); $hostname = trim($d['hostname'] ?? ''); $vendor = trim($d['vendor'] ?? ''); + // Respect explicit status from probe (e.g. phone probe knows if device is offline) + // Fall back to "online" for nmap results which only report reachable hosts + $status = in_array($d['status'] ?? '', ['online','offline']) ? $d['status'] : 'online'; if (!$ip) continue; $discoveredIPs[] = $ip; JarvisDB::execute( 'INSERT INTO network_devices (ip, mac, hostname, status, last_seen) - VALUES (?,?,?,"online",NOW()) + VALUES (?,?,?,?,NOW()) ON DUPLICATE KEY UPDATE mac = COALESCE(NULLIF(VALUES(mac),""), mac), hostname = COALESCE(NULLIF(VALUES(hostname),""), hostname), - status = "online", + status = VALUES(status), last_seen = NOW()', - [$ip, $mac ?: null, $hostname ?: $vendor ?: null] + [$ip, $mac ?: null, $hostname ?: $vendor ?: null, $status] ); if ($vendor) { JarvisDB::execute(