From c020936d7fc19978661e9ad3851e8635230e4141 Mon Sep 17 00:00:00 2001 From: Andrew Pimenov Date: Sun, 9 Aug 2026 02:30:15 +0300 Subject: [PATCH] icmp_win: guard windows-only imports so the module is importable cross-platform --- src/netcheck/probes/icmp_win.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/netcheck/probes/icmp_win.py b/src/netcheck/probes/icmp_win.py index 7393243..d800069 100644 --- a/src/netcheck/probes/icmp_win.py +++ b/src/netcheck/probes/icmp_win.py @@ -51,9 +51,12 @@ import ctypes import platform import socket import time -from ctypes import wintypes _REPLY_BUFFER_SIZE = 4096 +_IS_WINDOWS = platform.system() == "Windows" + +if _IS_WINDOWS: + from ctypes import wintypes class _IpOptionInformation(ctypes.Structure): @@ -77,6 +80,8 @@ def win_icmp_available() -> bool: def _handle(): + if not _IS_WINDOWS: + raise OSError("icmp_win backend is only available on Windows") iphlpapi = ctypes.WinDLL("Iphlpapi.dll") iphlpapi.IcmpCreateFile.restype = wintypes.HANDLE # argtypes must be declared for HANDLE-typed args: ctypes otherwise