mirror of
https://github.com/Horizontal42/netsleuth.git
synced 2026-11-11 01:02:10 +03:00
icmp_win: guard windows-only imports so the module is importable cross-platform
This commit is contained in:
parent
717068fa06
commit
c020936d7f
1 changed files with 6 additions and 1 deletions
|
|
@ -51,9 +51,12 @@ import ctypes
|
||||||
import platform
|
import platform
|
||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
from ctypes import wintypes
|
|
||||||
|
|
||||||
_REPLY_BUFFER_SIZE = 4096
|
_REPLY_BUFFER_SIZE = 4096
|
||||||
|
_IS_WINDOWS = platform.system() == "Windows"
|
||||||
|
|
||||||
|
if _IS_WINDOWS:
|
||||||
|
from ctypes import wintypes
|
||||||
|
|
||||||
|
|
||||||
class _IpOptionInformation(ctypes.Structure):
|
class _IpOptionInformation(ctypes.Structure):
|
||||||
|
|
@ -77,6 +80,8 @@ def win_icmp_available() -> bool:
|
||||||
|
|
||||||
|
|
||||||
def _handle():
|
def _handle():
|
||||||
|
if not _IS_WINDOWS:
|
||||||
|
raise OSError("icmp_win backend is only available on Windows")
|
||||||
iphlpapi = ctypes.WinDLL("Iphlpapi.dll")
|
iphlpapi = ctypes.WinDLL("Iphlpapi.dll")
|
||||||
iphlpapi.IcmpCreateFile.restype = wintypes.HANDLE
|
iphlpapi.IcmpCreateFile.restype = wintypes.HANDLE
|
||||||
# argtypes must be declared for HANDLE-typed args: ctypes otherwise
|
# argtypes must be declared for HANDLE-typed args: ctypes otherwise
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue