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,35 +10,23 @@ from evidence.models import Evidence, Annotation
from utils.constants import ALGOS, CHASSIS_DH 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']]
low_ix = None
lnets = []
nets = [x.split("\n") for x in hwinfo.split("\n\n") def get_mac(lshw):
if "network interface" in x and "Attached to" in x] nets = []
for n in nets: get_network_cards(json.loads(lshw), nets)
ix = None nets_sorted = sorted(nets, key=lambda x: x['businfo'])
mac = None # This funcion get the network card integrated in motherboard
for l in n: # integrate = [x for x in nets if "pci@0000:00:" in x.get('businfo', '')]
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: if nets_sorted:
mac = l.split(" ")[-1] return nets_sorted[0]['serial']
if ix and mac:
lnets.append((ix, mac))
if lnets:
lnets.sort()
mac = lnets[0][1]
print(f"MAC: {mac}")
return mac
class Build: class Build:
@ -112,8 +100,13 @@ class Build:
chassis = self.get_chassis_dh() chassis = self.get_chassis_dh()
serial_number = self.dmi.serial_number() serial_number = self.dmi.serial_number()
sku = self.get_sku() 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: if not mac:
print("WARNING!! No there are MAC address") print("WARNING!! No there are MAC address")
else: else: