From 48439373d517dadf0e7429cd21f6b7175f3ac464 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Tue, 18 Oct 2022 22:51:39 +0200 Subject: [PATCH] Patch for #19123 --- sensor.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sensor.py b/sensor.py index d0de743bfcdb..e66a64161565 100755 --- a/sensor.py +++ b/sensor.py @@ -971,16 +971,21 @@ def update_timer(): else: interfaces = set(_.strip() for _ in config.MONITOR_INTERFACE.split(',')) + try: + devices = pcapy.findalldevs() + except: + devices = [] + if (config.MONITOR_INTERFACE or "").lower() == "any": - if IS_WIN or "any" not in pcapy.findalldevs(): + if devices and (IS_WIN or "any" not in devices): print("[x] virtual interface 'any' missing. Replacing it with all interface names") - interfaces = pcapy.findalldevs() + interfaces = devices else: print("[?] in case of any problems with packet capture on virtual interface 'any', please put all monitoring interfaces to promiscuous mode manually (e.g. 'sudo ifconfig eth0 promisc')") for interface in interfaces: - if interface.lower() != "any" and re.sub(r"(?i)\Anetmap:", "", interface) not in pcapy.findalldevs(): - hint = "[?] available interfaces: '%s'" % ",".join(pcapy.findalldevs()) + if interface.lower() != "any" and devices and re.sub(r"(?i)\Anetmap:", "", interface) not in devices: + hint = "[?] available interfaces: '%s'" % ",".join(devices) exit("[!] interface '%s' not found\n%s" % (interface, hint)) print("[i] opening interface '%s'" % interface)