Fixes check for NPF service and add check for NPCAP service on Windows.

pull/565/head
grossmj 8 years ago
parent 2bb062c61e
commit acdc1e5ebb

@ -138,6 +138,21 @@ def is_interface_up(interface):
# TODO: Windows & OSX support # TODO: Windows & OSX support
return True return True
def _check_windows_service(service_name):
import pywintypes
import win32service
import win32serviceutil
try:
if win32serviceutil.QueryServiceStatus(service_name, None)[1] != win32service.SERVICE_RUNNING:
return False
except pywintypes.error as e:
if e.winerror == 1060:
return False
else:
raise aiohttp.web.HTTPInternalServerError(text="Could not check if the {} service is running: {}".format(service_name, e.strerror))
return True
def interfaces(): def interfaces():
""" """
@ -163,19 +178,8 @@ def interfaces():
"mac_address": mac_address}) "mac_address": mac_address})
else: else:
try: try:
import pywintypes if not _check_windows_service("npf") and not _check_windows_service("npcap"):
import win32service raise aiohttp.web.HTTPInternalServerError("The NPF or Npcap is not installed or running")
import win32serviceutil
try:
if win32serviceutil.QueryServiceStatus("npf", None)[1] != win32service.SERVICE_RUNNING:
raise aiohttp.web.HTTPInternalServerError(text="The NPF service is not running")
except pywintypes.error as e:
if e[0] == 1060:
raise aiohttp.web.HTTPInternalServerError(text="The NPF service is not installed")
else:
raise aiohttp.web.HTTPInternalServerError(text="Could not check if the NPF service is running: {}".format(e[2]))
results = get_windows_interfaces() results = get_windows_interfaces()
except ImportError: except ImportError:
message = "pywin32 module is not installed, please install it on the server to get the available interface names" message = "pywin32 module is not installed, please install it on the server to get the available interface names"

@ -168,7 +168,8 @@ def vmnet_windows(args, vmnet_range_start, vmnet_range_end):
os.system('"{}" -- add adapter vmnet{}'.format(vnetlib_path, vmnet_number)) os.system('"{}" -- add adapter vmnet{}'.format(vnetlib_path, vmnet_number))
os.system("net stop npf") os.system("net stop npf")
os.system("net start npf") os.system("net start npf")
os.system("net stop npcap")
os.system("net start npcap")
def vmnet_unix(args, vmnet_range_start, vmnet_range_end): def vmnet_unix(args, vmnet_range_start, vmnet_range_end):
""" """

Loading…
Cancel
Save