Compare commits

...

3 commits

Author SHA1 Message Date
Cayo Puigdefabregas 2ed33270ed get the first network card 2024-09-23 14:30:47 +02:00
Cayo Puigdefabregas d277e6cbaa fix bug 2024-09-23 14:14:30 +02:00
Cayo Puigdefabregas 756570c7b4 this get the integrate network card 2024-09-23 13:44:04 +02:00

View file

@ -10,36 +10,24 @@ from evidence.models import Evidence, Annotation
from utils.constants import ALGOS, CHASSIS_DH
def get_mac(hwinfo):
def get_network_cards(child, nets):
if child['id'] == 'network':
nets.append(child)
if child.get('children'):
[get_network_cards(x, nets) for x in child['children']]
def get_mac(lshw):
nets = []
low_ix = None
lnets = []
nets = [x.split("\n") for x in hwinfo.split("\n\n")
if "network interface" in x and "Attached to" in x]
for n in nets:
ix = None
mac = None
for l in n:
if "Attached to:" in l:
for v in l.split(" "):
if "#" in v:
ix = int(v.strip("#"))
if not low_ix:
low_ix = ix
if "HW Address:" in l:
mac = l.split(" ")[-1]
if ix and mac:
lnets.append((ix, mac))
get_network_cards(json.loads(lshw), nets)
nets_sorted = sorted(nets, 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']
if lnets:
lnets.sort()
mac = lnets[0][1]
print(f"MAC: {mac}")
return mac
class Build:
def __init__(self, evidence_json, user, check=False):
@ -112,8 +100,13 @@ class Build:
chassis = self.get_chassis_dh()
serial_number = self.dmi.serial_number()
sku = self.get_sku()
hwinfo_raw = snapshot["data"]["hwinfo"]
mac = get_mac(hwinfo_raw) or ""
if not snapshot["data"].get('lshw'):
return f"{manufacturer}{model}{chassis}{serial_number}{sku}"
lshw = snapshot["data"]["lshw"]
# mac = get_mac2(hwinfo_raw) or ""
mac = get_mac(lshw) or ""
if not mac:
print("WARNING!! No there are MAC address")
else: