Get a host's MAC address on Linux with C

0001-01-01

Linux malware may want to obtain MAC addresses for some reason. Here’s how to do it a few ways in C

using /sys/class/net iterate /sys/class/net’s directories with opendir/readdir/closedir read /sys/class/net/INTERFACE/address with fopen/fscanf/fclose

iterate over each interface and use ioctl SIOCGIFHWADDR

use getifaddrs(3)

popen(“ifconfig |grep HWaddr”)

using netlink/rtnetlink

https://stackoverflow.com/questions/1779715/how-to-get-mac-address-of-your-machine-using-a-c-program