Skip to content

Self-hosted homelab infrastructure visualizer — interactive network diagram with live status monitoring

fix: use correct ping args on Windows (-n/-w instead of -c/-W)

Pouzor07da498d182e
diff --git a/backend/app/services/status_checker.py b/backend/app/services/status_checker.py
index ef9b273..85b939e 100644
--- a/backend/app/services/status_checker.py
+++ b/backend/app/services/status_checker.py
@@ -2,6 +2,7 @@
import asyncio
import logging
import socket
+import sys
import time
from typing import Any
@@ -57,8 +58,12 @@ async def check_node(check_method: str, target: str | None, ip: str | None) -> d
async def _ping(host: str) -> bool:
+ if sys.platform == "win32":
+ args = ["ping", "-n", "1", "-w", "1000", host]
+ else:
+ args = ["ping", "-c", "1", "-W", "1", host]
proc = await asyncio.create_subprocess_exec(
- "ping", "-c", "1", "-W", "1", host,
+ *args,
stdout=asyncio.subprocess.DEVNULL,
stderr=asyncio.subprocess.DEVNULL,
)
diff --git a/backend/tests/test_status_checker.py b/backend/tests/test_status_checker.py
index 1824a99..3033127 100644
--- a/backend/tests/test_status_checker.py
+++ b/backend/tests/test_status_checker.py
@@ -3,7 +3,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
import pytest
-from app.services.status_checker import _tcp_connect, check_node
+from app.services.status_checker import _ping, _tcp_connect, check_node
# --- check_node dispatcher ---
@@ -149,6 +149,48 @@ async def test_check_node_exception_returns_offline():
assert result["response_time_ms"] is None
+# --- _ping platform args ---
+
+async def test_ping_uses_unix_args_on_non_windows():
+ captured = {}
+
+ async def fake_exec(*args, **kwargs):
+ captured["args"] = args
+ proc = MagicMock()
+ proc.returncode = 0
+ proc.wait = AsyncMock()
+ return proc
+
+ with patch("app.services.status_checker.sys.platform", "linux"), \
+ patch("asyncio.create_subprocess_exec", side_effect=fake_exec):
+ await _ping("192.168.1.1")
+
+ assert "-c" in captured["args"]
+ assert "-W" in captured["args"]
+ assert "-n" not in captured["args"]
+
+
+async def test_ping_uses_windows_args_on_win32():
+ captured = {}
+
+ async def fake_exec(*args, **kwargs):
+ captured["args"] = args
+ proc = MagicMock()
+ proc.returncode = 0
+ proc.wait = AsyncMock()
+ return proc
+
+ with patch("app.services.status_checker.sys.platform", "win32"), \
+ patch("asyncio.create_subprocess_exec", side_effect=fake_exec):
+ await _ping("192.168.1.1")
+
+ assert "-n" in captured["args"]
+ assert "-w" in captured["args"]
+ assert "-c" not in captured["args"]
+
+
# --- _tcp_connect ---
@pytest.mark.asyncio