From febf0f783965a07fac698fc048fc9afad6cec3cb Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Tue, 12 Jul 2016 13:09:08 +0200 Subject: [PATCH] Fix crash when winpcap is not installed Ref https://github.com/GNS3/gns3-gui/issues/1380 --- gns3server/utils/interfaces.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/gns3server/utils/interfaces.py b/gns3server/utils/interfaces.py index bb12151d..e58030b7 100644 --- a/gns3server/utils/interfaces.py +++ b/gns3server/utils/interfaces.py @@ -138,6 +138,7 @@ def is_interface_up(interface): # TODO: Windows & OSX support return True + def _check_windows_service(service_name): import pywintypes @@ -154,6 +155,7 @@ def _check_windows_service(service_name): raise aiohttp.web.HTTPInternalServerError(text="Could not check if the {} service is running: {}".format(service_name, e.strerror)) return True + def interfaces(): """ Gets the network interfaces on this server. @@ -178,13 +180,19 @@ def interfaces(): "mac_address": mac_address}) else: try: + service_installed = True if not _check_windows_service("npf") and not _check_windows_service("npcap"): - raise aiohttp.web.HTTPInternalServerError("The NPF or Npcap is not installed or running") - results = get_windows_interfaces() + service_installed = False + else: + results = get_windows_interfaces() except ImportError: message = "pywin32 module is not installed, please install it on the server to get the available interface names" raise aiohttp.web.HTTPInternalServerError(text=message) except Exception as e: log.error("uncaught exception {type}".format(type=type(e)), exc_info=1) raise aiohttp.web.HTTPInternalServerError(text="uncaught exception: {}".format(e)) + + if service_installed is False: + raise aiohttp.web.HTTPInternalServerError(text="The Winpcap or Npcap is not installed or running") + return results