S
Sam
I would like to use python to retrieve the mac address of the ethernet port. Can this be done? Thank you.
from uuid import getnode as get_mac
'%012x' % get_mac()
'18:03:73:cb:2a:ee'import uuid
s = "%12x" % uuid.getnode()
":".join(x+y for x, y in zip(s[::2], s[1::2]))
Andriy Kornatskyy said:Sam,
How about this?
from uuid import getnode as get_mac
'%012x' % get_mac()
James Harris said:AIUI that will return a mac address even if there isn't one. That may or may
not suit the OP.
To the OP, depending on what you want to do remember that a machine can have
more than one mac address and that a mac address can differ from the
burned-in address (BIA) as some cards allow the effective mac address to be
changed in software. So it's possible that two machines could show the same
mac address.
Sam,
How about this?
from uuid import getnode as get_mac
'%012x' % get_mac()
If you don't believe that two machines can have the same MAC address,
look up Hot Standby Router Protocol. And if you don't believe a machine
can ignore the BIA and assign a new MAC address in software, look up
Decnet <insert derogatory gesture with sound effect here>.
Chris Angelico said:We had a connection set up a few years
ago where the ISP tech recorded the source MAC into the far end, and
only that MAC would work - so when I stuck in a different router, I
needed to switch it to the old MAC before it could establish a
connection. Stupid? Yes. Unusual? I hope so
Chris Angelico said:We had a connection set up a few years
ago where the ISP tech recorded the source MAC into the far end, and
only that MAC would work - so when I stuck in a different router, I
needed to switch it to the old MAC before it could establish a
connection. Stupid? Yes. Unusual? I hope so
Actually, I think it's pretty common.
Sad.
I had exactly the same problem a few years ago. My DSL router fried
itself. I got a new one and it was easier to make it fake out the old
router's MAC than to get my carrier to update their head end
configuration[1].
[1] Roy's law of dealing with service providers. Anything you can do
yourself is easier than interfacing with tech support.
On 01/11/2014 07:35 AM, Andriy Kornatskyy wrote:
On Linux you could access the /sys/devices/virtual/net/<interface name>
file in the sysfs filesystem. I'm sure there are other ways.
Actually, I think it's pretty common.
The one I've used is to spawn a subprocess and run the "ifconfig" command with no arguments (which doesn't require any special privileges).
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.