Best way to extract MAC address from ifconfig's output?

Aman Jain picture Aman Jain · Oct 29, 2008 · Viewed 96.5k times · Source

What is the best way to extract the MAC address from ifconfig's output?

Sample output:

bash-3.00# ifconfig eth0        
eth0      Link encap:Ethernet  HWaddr 1F:2E:19:10:3B:52    
          inet addr:127.0.0.66  Bcast:127.255.255.255  Mask:255.0.0.0    
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          ....
          ....

Should I use cut, AWK or anything else, and what are the merits and demerits of one method over the other.

Answer

Michalis picture Michalis · Jun 13, 2011

You can do a cat under /sys/class/

cat /sys/class/net/*/address

Specifically for eth0

cat /sys/class/net/eth0/address