Getting Local MAC Address

Steve Holden steve at holdenweb.com
Fri Apr 2 18:18:36 EDT 2010


Booter wrote:
> Hello all,
> 
> I am new to python ans was wondering if there was a way to get the mac
> address from the local NIC?
> 
> Thanks for your help.
> 
>>> import uuid
>>> uuid.getnode()
246090452741227L
>>>

This is supposed to return the MAC address, but I am not sure it does.
The documentation says:

"""
getnode( )

Get the hardware address as a 48-bit positive integer. The first time
this runs, it may launch a separate program, which could be quite slow.
If all attempts to obtain the hardware address fail, we choose a random
48-bit number with its eighth bit set to 1 as recommended in RFC 4122.
"Hardware address" means the MAC address of a network interface, and on
a machine with multiple network interfaces the MAC address of any one of
them may be returned.
"""

So the return value isn't *guaranteed* to be an ethernet address, and
I'm not sure whether that code gets any regular testing.

regards
 Steve
-- 
Steve Holden           +1 571 484 6266   +1 800 494 3119
See PyCon Talks from Atlanta 2010  http://pycon.blip.tv/
Holden Web LLC                 http://www.holdenweb.com/
UPCOMING EVENTS:        http://holdenweb.eventbrite.com/




More information about the Python-list mailing list