How to get Mac address of ethernet port?

Michael Torrie torriem at gmail.com
Sat Jan 11 11:34:35 EST 2014


On 01/11/2014 07:35 AM, Andriy Kornatskyy wrote:
> Sam,
> 
> How about this?
> 
> from uuid import getnode as get_mac
> '%012x' % get_mac()

This seems to work if you have only one ethernet adapter.  Most
computers have two (wired and wireless) adapters.

Getting a mac address is platform-specific, and the OP has not specified
what OS he is using.

On Windows I imagine you'd have to access the WMI subsystem in Windows.

On Linux you could access the /sys/devices/virtual/net/<interface name>
file in the sysfs filesystem.  I'm sure there are other ways.

No idea on OS X.



More information about the Python-list mailing list