Finding original MAC address from Hardware itself

a 夏天 提交于 2019-12-03 04:20:33

Certainly in ethtool 3.1 you can just print the address: ethtool -P|--show-permaddr DEVNAME Show permanent hardware address

e.g.

ethtool -P eth0

Permanent address: 94:de:80:6a:21:25

Try cat /sys/class/net/eth0/address or cat /sys/class/net/em1/address if using Fedora. It should work.

The original answer is here: Notes of a Systems Admin

The only way to find the original MAC address is to use the same method the network card driver does - unfortunately, I don't believe there is a generic way to tell the driver to provide it's MAC address "as provided by the hardware". Of course, there are cases where there isn't a hardware network card for that particular interface - virtual network drivers for virtualization and when using bridges and software switches for example.

And of course, the hardware may be such that you can't actually read the "original" MAC address when it has been overwritten by software, because there is only one set of registers for the MAC address itself.

I had a quick look at the pcnet32.c drivers (because it's one of the models of network card that I have a rough idea how it works and where the different registers are, etc, so I can see what it does). As far as I can see, it supports no method of actually asking "what is your PROM ethernet address" - the MAC address is read out during the "probe1" section of the module initialization, and stored away. No further access to those hardware registers is made.

Well, the old ethernet address remains in the first bytes of the card eeprom (at least for some types of cards), so it is possible to extract it using ethtool

bash$ sudo ethtool -e eth1
Offset      Values
------      ------
0x0000      tt uu ww xx yy zz 79 03 
0x....

where tt:uu:ww:xx:yy:zz is old mac address

user3462738

This may not be the programmatic way, but why not search dmesg. All of my machines' NICs spit out the MAC address at detection time.

Try something like this:

dmesg|grep eth0

Different NICs display the MAC address differently, but the log will always contain the kernel given name of the adapter (in most cases eth0 or wlan0).

This command lists all the ethernet devices and original HW addresses.

dmesg | grep eth | grep IRQ | awk {'print "permanent address of " $5 " " $9'} |tr "," " "
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!