getting MAC address of system: eth0 vs PredictableNetworkInterfaceNames
0
votes
2
answers
3444
views
I wrote some C code having a rudimentary software licensing function within, where the executable will only run if the MAC address of the system I whitelisted in my C code. I only want this to work in linux.
I was accessing
/sys/class/net/eth0/address
which contains something like a0:b1:c2:d3:e4:f5
all in lower case on one line, making it very easy to get the MAC address. This works only if you have eth0
because I hard coded fopen( "/sys/class/net/eth0/address", "r" );
The problem I am realizing is the **eth0** part. With BiosDevName and/or Predictable Network Interface Naming being the default now [in RHEL/CentOS 7] I am seeing something like eno1
rather than eth0
as the first network device having a MAC address. And this can vary greatly from system to system.
So I am dealing with /sys/class/net//address
.
What is the most portable and reliable, and not to hard, of a way to get the MAC address(es) of a linux system? Oftentimes the servers I deal with have quad port Intel NIC's, but I really only need the first one. And my code doesn't care what the network interface names are, I just need to know one or more MAC addresses that are present.
Asked by ron
(8647 rep)
Jan 20, 2020, 06:16 PM
Last activity: Jul 27, 2025, 12:03 AM
Last activity: Jul 27, 2025, 12:03 AM