Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 923
Aman Jain Avatar asked Oct 29 '08 05:10

Aman Jain


People also ask

Does ifconfig show MAC address?

On a Linux machine Open a terminal window. Type ifconfig at the command prompt. Your MAC address will be displayed beside the label HWaddr.

How do I find the MAC address of an interface?

Windows 10 (alternate method)Go to Start > Settings. Once the Settings page opens click on Network & Internet. Select Ethernet from the left hand side and select your Ethernet interface on the right hand side. The Mac address will be displayed next to Physical address and is a 12 character alpha numeric string.

How do I find the MAC address of a Linux machine?

UNIX or Linux devicesOpen a terminal. Type ifconfig -a and press Enter. -> HWaddr or ether or lladdr is the device's MAC address.

How can I get a list of all MAC addresses?

To see all the MAC addresses and their associated IP addresses, type “arp -a”. This command will list all the available MAC addresses in the system.


1 Answers

You can do a cat under /sys/class/

cat /sys/class/net/*/address 

Specifically for eth0

cat /sys/class/net/eth0/address 
like image 195
Michalis Avatar answered Oct 11 '22 22:10

Michalis