[Pythonmac-SIG] Obtaining the hardware address of the first network card
Bob Ippolito
bob@redivi.com
Sat, 13 Apr 2002 10:16:41 -0400
Each ethernet controller in every OS I've ever used has an index number
(thats where en0, en1,.. enX come from), in OS X it's the order in which
they're detected by the kernel. You can find it out with sysctl and
ioctl (I don't remember if you need to use ioctl for reading network
info though, but you definitely do for writing).. they're both more or
less talking to the kernel "directly". afaik there isn't a more high
level way other than spawning a copy of ifconfig or maybe nidump
(theoretically, but i dont think that ethers is populated in NetInfo
yet) or something. You could of course always look at the source for
ifconfig if you were stumped, it is readily available in the Darwin CVS
repository (which can probably even be browsed online). I actually
think Apple may have written a tutorial on this
I have no idea how you would do it on OS9.
man 3 sysctl and man 3 ioctl should tell you most of what you need to
know for OS X, unfortunately these aren't available from python and
aren't cross-platform (for doing what you want to do) anyways.
Basically you're either going to have to write a C module to do it
(especially, I would think, for OS9) that you could actually adapt to
other platforms (the other unix-likes and win32) or find some nasty set
of kludges.
I'm guessing he's looking for a "serial number" for the computer for
some sort of authentication or verification, in which case the ethernet
adapter with the lowest index makes the most sense, since it is most
likely (especially with modern macs) to be grafted onto the motherboard
and reporting its unique MAC address whether or not the user wants it to.
-bob
On Friday, April 12, 2002, at 02:10 AM, Deirdre Saoirse Moen wrote:
> At 12:18 AM +0200 4/12/02, Pieter Claerhout wrote:
>> is there a way to obtain the hardware address of the built-in network
>> card
>> of your Mac using Python? I found way to get it under command line
>> python in
>> OS X, but it should work on all macintoshes...
>
> In theory, there could be multiple addresses, so how do you presume to
> figure out which one? And some Macs don't have ethernet. :)