refs #1093 rebuild ogGetMacAddress

pull/1/head
Antonio Guerrero 2024-11-13 00:19:04 -06:00
parent 3058a3798f
commit 646090da3c
1 changed files with 35 additions and 17 deletions

View File

@ -196,26 +196,44 @@ def ogGetIpAddress():
#@return str_ether - Dirección Ethernet #@return str_ether - Dirección Ethernet
#*/ ## #*/ ##
def ogGetMacAddress(): def ogGetMacAddress():
MAC = "" try:
if "DEVICE" in os.environ:
device = os.environ["DEVICE"]
result = subprocess.run(
["ip", "-o", "link", "show", "up", "dev", device],
capture_output=True,
text=True,
check=True
).stdout
else:
result = subprocess.run(
["ip", "-o", "link", "show", "up"],
capture_output=True,
text=True,
check=True
).stdout
if len(sys.argv) >= 2 and sys.argv[1] == "help": mac_addresses = []
SystemLib.ogHelp("ogGetMacAddress", "ogGetMacAddress", "ogGetMacAddress => 00:11:22:33:44:55") for line in result.splitlines():
return if "link/ether" in line:
parts = line.split()
for i, part in enumerate(parts):
if part == "link/ether":
mac_addresses.append(parts[i + 1].upper())
# Obtener direcciones Ethernet. if mac_addresses:
if "DEVICE" in os.environ: print(mac_addresses[0])
MAC = subprocess.run(["ip", "-o", "link", "show", "up", "dev", os.environ["DEVICE"]], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL).stdout.decode().split() return mac_addresses[0]
MAC = [addr.upper() for addr in MAC if "ether" in addr] else:
else: print("No active mac address found")
MAC = subprocess.run(["ip", "-o", "link", "show", "up"], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL).stdout.decode().split() return None
MAC = [addr.upper() for addr in MAC if "ether" in addr and "lo" not in addr]
# Mostrar solo la primera.
if MAC:
print(MAC[0])
return 0
except subprocess.CalledProcessError as e:
print(f"Error executing ip command: {e.stderr}")
return None
except Exception as e:
print(f"Unexpected error: {str(e)}")
return None
#/** #/**
# ogGetNetInterface # ogGetNetInterface