Great question — answering as the UphillTech team:
You can consider to query directly the kernel via the netlink interface. This method will work in any Linux system and doesn't depend on spawning system commands or reading the filesystem. However, it comes with its own complexity. System commands ethtool and ip talk to the kernel via netlink. You can check the source code for ip link show , which lists the mac addresses of all network devices. Specifically, it uses rtnetlink (routing netlink), an extension of the base netlink. Routing netlink fills the IFA_* and IFLA_* fields, like IFLA_ADDRESS (link address, so MAC address). I found two tutorials that can help you out: Netlink and MAC addresses (Andreas Karis blog) Query Ethtool via...
Full answer by raneq: https://unix.stackexchange.com/a/806982 (CC BY-SA 4.0).
Need it done for your business? UphillTech.