PDA

View Full Version : Retrieving MAC address programmatically



HunterSBuntu
October 24th, 2007, 12:21 AM
Does anyone have any recommendations on how to retrieve a MAC address programmatically?

So far I'm looking at doing a system call to ifconfig, piping that and parsing the output to get the MAC address. I can't help but feel that there should be a more elegant way of getting this info that I may have overlooked.

Are there any other methods that I can use to query network hardware for this sort of information?

FXEF
October 24th, 2007, 12:57 AM
Does anyone have any recommendations on how to retrieve a MAC address programmatically?

So far I'm looking at doing a system call to ifconfig, piping that and parsing the output to get the MAC address. I can't help but feel that there should be a more elegant way of getting this info that I may have overlooked.

Are there any other methods that I can use to query network hardware for this sort of information?

This will list your MAC.

/sbin/ifconfig | grep HWaddr

here's another way

lshw | grep serial

FXEF

angustia
October 24th, 2007, 01:18 AM
cat /sys/class/net/ath0/address

stair314
May 10th, 2009, 06:51 AM
You could install libnet and use libnet_get_hwaddr().