LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   obtaining the MAC of the interfaces (https://www.linuxquestions.org/questions/linux-newbie-8/obtaining-the-mac-of-the-interfaces-884290/)

danndp 06-03-2011 04:33 AM

obtaining the MAC of the interfaces
 
Hi,

I'm running this command, and seems not to work, following the command:

Quote:

for nic in `ls /sys/class/net | grep -v lo`; do echo ${nic}; udevinfo -a -p /class/net/{nic} | grep -i address; done
The output is the following:

Quote:

eth0
eth1
But the output should show something like this: (showing the MAC address)

Quote:

eth0
SYSFS{address}=="00:26:55:df:5d:ba"
eth1
SYSFS{address}=="00:26:55:df:5d:b9"
Am i missing something with the command?

Regards!

ButterflyMelissa 06-03-2011 04:39 AM

Yo!

Quote:

Am i missing something with the command?
yes...you're using the wrong command IMHO... :)

Use

Quote:

arp -a
to see the MAC of the nic's in the box...

Wellness

Thor

blue_print 06-03-2011 04:44 AM

Looks like, the for loop is not correct. Please use the following one, it will work.
Code:

for nic in `ls /sys/class/net | grep -v lo`; do echo ${nic}; udevinfo -a -p /sys/class/net/${nic}/address | grep -i address | grep -v looking | grep -v KERNEL; done

danndp 06-03-2011 04:46 AM

Quote:

yes...you're using the wrong command IMHO... :)
Well, i found the mistake =) the command should be like this:

Quote:

for nic in `ls /sys/class/net | grep -v lo`; do echo ${nic}; udevinfo -a -p /class/net/${nic} | grep -i address; done
As you can see, i missed a $ =)

Many thanks for your help

Regards!

danndp 06-03-2011 04:47 AM

Quote:

Originally Posted by blue_print (Post 4374922)
Looks like, the for loop is not correct. Please use the following one, it will work.
Code:

for nic in `ls /sys/class/net | grep -v lo`; do echo ${nic}; udevinfo -a -p /sys/class/net/${nic}/address | grep -i address | grep -v looking | grep -v KERNEL; done

THANKS blue print =)

ButterflyMelissa 06-03-2011 04:48 AM

Thanks!

I learned something here :D

THor

jschiwal 06-03-2011 04:54 AM

You could get the MAC address from the contents of the /sys/class/net/*/address file.


All times are GMT -5. The time now is 04:49 AM.