fixed mac retrieval
This commit is contained in:
parent
434c518eec
commit
21b1f07151
|
@ -5,23 +5,15 @@ import logging
|
|||
from dmidecode import DMIParse
|
||||
from json_repair import repair_json
|
||||
|
||||
from evidence.parse_details import get_lshw_child
|
||||
from evidence.models import Annotation
|
||||
from evidence.xapian import index
|
||||
from utils.constants import CHASSIS_DH
|
||||
|
||||
|
||||
logger = logging.getLogger('django')
|
||||
|
||||
|
||||
def get_network_cards(child, nets):
|
||||
if child['id'] == 'network' and "PCI:" in child.get("businfo"):
|
||||
nets.append(child)
|
||||
if child.get('children'):
|
||||
[get_network_cards(x, nets) for x in child['children']]
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def get_mac(lshw):
|
||||
nets = []
|
||||
try:
|
||||
if type(lshw) is dict:
|
||||
hw = lshw
|
||||
|
@ -30,19 +22,17 @@ def get_mac(lshw):
|
|||
except json.decoder.JSONDecodeError:
|
||||
hw = json.loads(repair_json(lshw))
|
||||
|
||||
try:
|
||||
get_network_cards(hw, nets)
|
||||
except Exception as ss:
|
||||
print("WARNING!! {}".format(ss))
|
||||
return
|
||||
networks = []
|
||||
get_lshw_child(hw, networks, 'network')
|
||||
|
||||
nets_sorted = sorted(nets, key=lambda x: x['businfo'])
|
||||
nets_sorted = sorted(networks, key=lambda x: x['businfo'])
|
||||
# This funcion get the network card integrated in motherboard
|
||||
# integrate = [x for x in nets if "pci@0000:00:" in x.get('businfo', '')]
|
||||
|
||||
if nets_sorted:
|
||||
return nets_sorted[0]['serial']
|
||||
|
||||
mac = nets_sorted[0]['serial']
|
||||
logger.debug("The snapshot has the following MAC: %s" , mac)
|
||||
return mac
|
||||
|
||||
class Build:
|
||||
def __init__(self, evidence_json, user, check=False):
|
||||
|
|
Loading…
Reference in a new issue