fix: re-scan updates services on existing pending devices instead of skipping

This commit is contained in:
Pouzor
2026-03-07 23:09:54 +01:00
parent d98bfba506
commit 6e6041d871
+21 -16
View File
@@ -115,27 +115,32 @@ async def run_scan(ranges: list[str], db: AsyncSession, run_id: str) -> None:
services = fingerprint_ports(host["open_ports"]) services = fingerprint_ports(host["open_ports"])
suggested_type = suggest_node_type(host["open_ports"]) suggested_type = suggest_node_type(host["open_ports"])
# Skip if already pending (by IP) # Update existing pending device or create a new one
existing = await db.execute( existing_result = await db.execute(
select(PendingDevice).where( select(PendingDevice).where(
PendingDevice.ip == host["ip"], PendingDevice.ip == host["ip"],
PendingDevice.status == "pending", PendingDevice.status == "pending",
) )
) )
if existing.scalar_one_or_none(): existing = existing_result.scalar_one_or_none()
continue if existing:
existing.mac = host.get("mac") or existing.mac
device = PendingDevice( existing.hostname = host.get("hostname") or existing.hostname
ip=host["ip"], existing.os = host.get("os") or existing.os
mac=host.get("mac"), existing.services = services
hostname=host.get("hostname"), existing.suggested_type = suggested_type
os=host.get("os"), else:
services=services, device = PendingDevice(
suggested_type=suggested_type, ip=host["ip"],
status="pending", mac=host.get("mac"),
) hostname=host.get("hostname"),
db.add(device) os=host.get("os"),
devices_found += 1 services=services,
suggested_type=suggested_type,
status="pending",
)
db.add(device)
devices_found += 1
# Commit immediately so the device is visible right away # Commit immediately so the device is visible right away
await db.commit() await db.commit()