Compare commits
3 commits
ebe80ffea6
...
2ed33270ed
Author | SHA1 | Date | |
---|---|---|---|
2ed33270ed | |||
d277e6cbaa | |||
756570c7b4 |
|
@ -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:
|
||||||
|
|
Loading…
Reference in a new issue