fixed geting mac
This commit is contained in:
parent
b36636d28e
commit
bdaaa2740d
|
@ -13,22 +13,30 @@ from utils.constants import ALGOS, CHASSIS_DH
|
||||||
def get_mac(hwinfo):
|
def get_mac(hwinfo):
|
||||||
|
|
||||||
low_ix = None
|
low_ix = None
|
||||||
|
lnets = []
|
||||||
|
|
||||||
nets = [x.split("\n") for x in hwinfo.split("\n\n")
|
nets = [x.split("\n") for x in hwinfo.split("\n\n")
|
||||||
if "network interface" in x and "Attached to" in x]
|
if "network interface" in x and "Attached to" in x]
|
||||||
|
|
||||||
for n in nets:
|
for n in nets:
|
||||||
ix = None
|
ix = None
|
||||||
if "Attached to:" in n:
|
mac = None
|
||||||
for v in c.split(" "):
|
for l in n:
|
||||||
|
if "Attached to:" in l:
|
||||||
|
for v in l.split(" "):
|
||||||
if "#" in v:
|
if "#" in v:
|
||||||
ix = int(v.strip("#"))
|
ix = int(v.strip("#"))
|
||||||
if not low_ix:
|
if not low_ix:
|
||||||
low_ix = ix
|
low_ix = ix
|
||||||
|
|
||||||
if "HW Address:" in n:
|
if "HW Address:" in l:
|
||||||
if low_ix <= ix:
|
mac = l.split(" ")[-1]
|
||||||
mac = c.split(" ")[-1]
|
if ix and mac:
|
||||||
|
lnets.append((ix, mac))
|
||||||
|
|
||||||
|
if lnets:
|
||||||
|
lnets.sort()
|
||||||
|
mac = lnets[0][1]
|
||||||
print(f"MAC: {mac}")
|
print(f"MAC: {mac}")
|
||||||
return mac
|
return mac
|
||||||
|
|
||||||
|
@ -108,6 +116,5 @@ class Build:
|
||||||
mac = get_mac(hwinfo_raw) or ""
|
mac = get_mac(hwinfo_raw) or ""
|
||||||
if not mac:
|
if not mac:
|
||||||
print("WARNING!! No there are MAC address")
|
print("WARNING!! No there are MAC address")
|
||||||
print(f"{manufacturer}{model}{chassis}{serial_number}{sku}{mac}")
|
|
||||||
|
|
||||||
return f"{manufacturer}{model}{chassis}{serial_number}{sku}{mac}"
|
return f"{manufacturer}{model}{chassis}{serial_number}{sku}{mac}"
|
||||||
|
|
Loading…
Reference in New Issue