Os:REDHAT LINUX Linux manage: 2.6.18.8-1 #
Is this possible to read MAC address form NIC directly ? I have below code but it just read from above layer but not the card itself !!!
I'm trying to figure out how to find the original MAC address of an ethernet NIC on my linux box. I understand how to find the current MAC address using ifconfig, but if the address has been changed, say by using 'ifconfig eth0 hw ether uu:vv:ww:yy:xx:zz'
,or I set "permanent" it using vi /etc/sysconfig/network-scripts/ifcfg-eth0
.this file...I can successfully UP
it in REBOOT
also. how do I find the original? There must be a way to find it, because it is still burned permanently into the card, but I can't find a tool to read the burned in address. is there any utility for it or command for it? I suppose to write C code for it. but don't know how to do this in above case.
** below code gives my current MAC but not original MAC
#include <stdio.h> /* Standard I/O */ #include <stdlib.h> /* Standard Library */ #include <errno.h> /* Error number and related */ #define ENUMS #include <sys/socket.h> #include <net/route.h> #include <net/if.h> #include <features.h> /* for the glibc version number */ #if __GLIBC__ >= 2 && __GLIBC_MINOR >= 1 #include <netpacket/packet.h> #include <net/ethernet.h> /* the L2 protocols */ #else #include <asm/types.h> #include <linux/if_packet.h> #include <linux/if_ether.h> /* The L2 protocols */ #endif #include <netinet/in.h> #include <arpa/inet.h> #include <sys/un.h> #include <sys/ioctl.h> #include <netdb.h> int main( int argc, char * argv[] ){ unsigned char mac[IFHWADDRLEN]; int i; get_local_hwaddr( argv[1], mac ); for( i = 0; i < IFHWADDRLEN; i++ ){ printf( "%02X:", (unsigned int)(mac[i]) ); } } int get_local_hwaddr(const char *ifname, unsigned char *mac) { struct ifreq ifr; int fd; int rv; // return value - error value from df or ioctl call /* determine the local MAC address */ strcpy(ifr.ifr_name, ifname); fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP); if (fd < 0) rv = fd; else { rv = ioctl(fd, SIOCGIFHWADDR, &ifr); if (rv >= 0) /* worked okay */ memcpy(mac, ifr.ifr_hwaddr.sa_data, IFHWADDRLEN); } return rv; }
Right click on the network adapter and click on Properties. Click on Configure and select the Advanced tab. In the Property list locate Network Address. If Not Present is selected on the right then the NIC is using the original MAC address.
Select a virtual machine, right-click, and select Properties. Click the Hardware tab and in the NICs section, select Reset from the MAC Address drop-down menu.. Click OK.
No two devices on a local network should ever have the same MAC address. If that does happen, both devices will have communications problems because the local network will get confused about which device should receive the packet.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With