Added conditional import of netifaces

This commit is contained in:
Mark Qvist 2021-12-01 11:46:19 +01:00
parent f5236878b0
commit 10854bfdbc
2 changed files with 4 additions and 4 deletions

View File

@ -286,7 +286,7 @@ class TCPServerInterface(Interface):
@staticmethod
def get_address_for_if(name):
import importlib
if importlib.find_loader('netifaces') != None:
if importlib.util.find_spec('netifaces') != None:
import netifaces
return netifaces.ifaddresses(name)[netifaces.AF_INET][0]['addr']
else:
@ -297,7 +297,7 @@ class TCPServerInterface(Interface):
@staticmethod
def get_broadcast_for_if(name):
import importlib
if importlib.find_loader('netifaces') != None:
if importlib.util.find_spec('netifaces') != None:
import netifaces
return netifaces.ifaddresses(name)[netifaces.AF_INET][0]['broadcast']
else:

View File

@ -12,7 +12,7 @@ class UDPInterface(Interface):
@staticmethod
def get_address_for_if(name):
import importlib
if importlib.find_loader('netifaces') != None:
if importlib.util.find_spec('netifaces') != None:
import netifaces
return netifaces.ifaddresses(name)[netifaces.AF_INET][0]['addr']
else:
@ -23,7 +23,7 @@ class UDPInterface(Interface):
@staticmethod
def get_broadcast_for_if(name):
import importlib
if importlib.find_loader('netifaces') != None:
if importlib.util.find_spec('netifaces') != None:
import netifaces
return netifaces.ifaddresses(name)[netifaces.AF_INET][0]['broadcast']
else: