Re: How to get Mac address of ethernet port?
On Tue, Jan 14, 2014 at 2:42 AM, William Ray Wing wrote: > 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). Very small caveat: On some systems, running ifconfig doesn't require privileges, but it's not in the unprivileged user's default path (it's in root's path though). I've seen this on Debian Linux, for instance. So you may need to explicitly call /sbin/ifconfig or whereever it's stored. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: How to get Mac address of ethernet port?
On Jan 11, 2014, at 11:34 AM, Michael Torrie wrote: > 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/ > file in the sysfs filesystem. I'm sure there are other ways. > > No idea on OS X. > -- > https://mail.python.org/mailman/listinfo/python-list There are probably several ways in OS-X, just as there are in any other UNIX system. 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). This will return a string of all the network interfaces (including the loopback and firewire interfaces in addition to Ethernet and WiFi) and their config specs. The OP would then parse this string looking for the location of the phrase "status: active" and then back up to the mac address that precedes it. More work than using uuid, but this guarantees a current and correct answer. >>> import string >>> import subprocess >>> mac_result = subprocess.Popen(['ifconfig'], stderr = subprocess.PIPE, >>> stdout = subprocess.PIPE).communicate()[0] >>> mac_loc = string.find(mac_result, "status: active") ...and so on. Bill -- https://mail.python.org/mailman/listinfo/python-list
Re: How to get Mac address of ethernet port?
On Sunday, January 12, 2014 12:34:35 AM UTC+8, Michael Torrie wrote: > On 01/11/2014 07:35 AM, Andriy Kornatskyy wrote: > > > On Linux you could access the /sys/devices/virtual/net/ > > file in the sysfs filesystem. I'm sure there are other ways. > Thank you to everyone for the helpful answers. I am using Linux in this case. I think this is the direction I am looking for. Thanks! -- https://mail.python.org/mailman/listinfo/python-list
Re: How to get Mac address of ethernet port?
On Sun, Jan 12, 2014 at 8:55 AM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> 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. Unless you expect that doing it yourself will take upwards of an hour, don't even bother talking to tech support, at least with the ISPs I know. There's only *ONE* time when I got results quicker than that (or, say, half an hour absolute minimum): with iiNet, I rang their support and got dropped into a classic IVR system, and one of the options was "Press whatever to get the basic setup information for your connection". A couple more prompts and I was given a prerecorded pile of numbers and settings, one of which was the exact one I was having trouble with. With any other kind of business, this sort of thing belongs on the web site, but for obvious reasons that's less useful for an ISP :) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: How to get Mac address of ethernet port?
In article , Chris Angelico wrote: > 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. 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. -- https://mail.python.org/mailman/listinfo/python-list
Re: How to get Mac address of ethernet port?
On Sun, Jan 12, 2014 at 3:29 AM, Roy Smith wrote: > 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 . Most people shouldn't have to worry about MAC address duplication/collision on the same subnet (I used MACs as a means of guaranteeing uniqueness among a pool of application servers, for instance), but MAC switching in software can occur in a typical home internet connection scenario. 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, but still more likely than coming across DECnet in a typical home! ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: How to get Mac address of ethernet port?
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/ file in the sysfs filesystem. I'm sure there are other ways. No idea on OS X. -- https://mail.python.org/mailman/listinfo/python-list
Re: How to get Mac address of ethernet port?
In article , "James Harris" wrote: > "Andriy Kornatskyy" wrote in message > news:mailman.5329.1389450993.18130.python-l...@python.org... > > Sam, > > > > How about this? > > > > from uuid import getnode as get_mac > > '%012x' % get_mac() > > AIUI that will return a mac address even if there isn't one. That may or may > not suit the OP. Specifically, it says, "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". Keep in mind that 4122 is all about generating globally unique strings. The only reason it even talks about MAC addresses is in the context of one possible way to generate uuids. If your goal is to get the MAC address for some sort of networking reason, you need to bear in mind what James says below: > 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. 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 . -- https://mail.python.org/mailman/listinfo/python-list
Re: How to get Mac address of ethernet port?
"Andriy Kornatskyy" wrote in message news:mailman.5329.1389450993.18130.python-l...@python.org... > Sam, > > How about this? > > from uuid import getnode as get_mac > '%012x' % get_mac() 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. James -- https://mail.python.org/mailman/listinfo/python-list
Re: How to get Mac address of ethernet port?
This is slightly longer than ChrisA's second solution: >>> import uuid >>> s = "%12x" % uuid.getnode() >>> ":".join(x+y for x, y in zip(s[::2], s[1::2])) '18:03:73:cb:2a:ee' Skip -- https://mail.python.org/mailman/listinfo/python-list
Re: How to get Mac address of ethernet port?
On Sun, Jan 12, 2014 at 1:35 AM, Andriy Kornatskyy wrote: > from uuid import getnode as get_mac > '%012x' % get_mac() > Code golf! Put colons in that, with as little code as possible. # Way too verbose. import uuid l=list("%012x"%uuid.getnode()) l[10:10]=l[8:8]=l[6:6]=l[4:4]=l[2:2]=':' mac = ''.join(l) # Shorter but not short enough import uuid s="%012x"%uuid.getnode() mac = ':'.join(s[i*2:i*2+2] for i in range(6)) :) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: How to get Mac address of ethernet port?
On Sun, Jan 12, 2014 at 1:26 AM, Sam wrote: > I would like to use python to retrieve the mac address of the ethernet port. > Can this be done? Thank you. > Did you try searching the web for 'python retrieve mac address' or similar? There are several options offered. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: How to get Mac address of ethernet port?
Sam, How about this? from uuid import getnode as get_mac '%012x' % get_mac() Thanks. Andriy Kornatskyy On Jan 11, 2014, at 4:26 PM, Sam wrote: > I would like to use python to retrieve the mac address of the ethernet port. > Can this be done? Thank you. > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
How to get Mac address of ethernet port?
I would like to use python to retrieve the mac address of the ethernet port. Can this be done? Thank you. -- https://mail.python.org/mailman/listinfo/python-list