[futurebasic] RE: MAC address

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : July 2003 : Group Archive : Group : All Groups

From: Ken Shmidheiser <kshmidheiser@...>
Date: Mon, 21 Jul 2003 11:32:12 -0400
David Cox wrote:

>I need to track the number of individual Macs who are using my FB
>application. I was thinking of using the ethernet card's MAC address
>and writing it to a file. Does anyone know how to get the MAC address
>from FB?

Robert P. added:

>This tech note is pre-OS X, but still worth reading:
><http://developer.apple.com/technotes/tn/tn1103.html>
>It has a link to sample code and a demo app for getting the MAC
>address.  The demo app doesn't work on OS X.


If you wish to obtain the ethernet card address found in Apple Menu 
-> System Preferences -> Network, TCP/IP tab in OS X, here is one 
method:

(Standard warning: Watch for e-mail line breaks and lost constant underscores.)

// ----------- begin code -----------



/*
     A quick-n-dirty way to obtain your ethernet
     card MAC address in OS X with FB^3. (This
     number can be double checked in the Network
     System Preferences under the TCP/IP tab)

     Example by Ken Shmidheiser
     July 20, 2003

*/
local fn EthernetCardMACAddress$
dim as str255 enetMACStr

long if system(_sysVers) => 1000
open "UNIX",1,"echo `ifconfig -a | awk /ether/'{ print $2 }'`"
do
line input #1, enetMACStr
if enetMACStr > "" then exit fn
until eof(1)
close 1
xelse
enetMACStr = "error"
end if

end fn = enetMACStr

print "Your current ethernet card's MAC address is:
print
print fn EthernetCardMACAddress$

include "Subs Quick Event Loop.Incl"



// ----------- end code -------------


Caveat coder:

Using the Ethernet card address once was a semi-viable way of 
uniquely identifying a Macintosh.

Today it is fraught with danger.

For instance, Mac's with an Airport card have two address as do 
notebooks with external ethernet cards or Macs with multiple ethernet 
cards and Airport. The active MAC address will change dependent on 
the device in use at the time. It also is possible for a user to 
change his card's address-- particularly on older machines-- simply 
by changing one resource value.

Robert Purves' direction toward tn1103 is a good step for code for 
older operating systems. There also is another possibility, the free 
UUIDLib for the Macintosh:

http://www.pandawave.com/uuidlib.html

At install, UUIDLib takes the ethenet card MAC address and the 
current time and creates a unique code that is stored in a preference 
file. The software then checks for the preference file key upon 
launch. The downside here is that theoretically the preference file 
could be copied to other machines to allow the software to run on 
them.

You may also wish to review the following, some of which demonstrate 
approved methods of obtaining hardware addresses in OS X and earlier.

http://developer.apple.com/samplecode/Sample_Code/Networking/GetEnetAddrDirect.ppc/GetEnetAddrDirect.c.htm

http://developer.apple.com/samplecode/Sample_Code/Networking/GetHWEthernetAddr.htm

http://developer.apple.com/samplecode/Sample_Code/Networking/GetMACAddressSample.htm

http://developer.apple.com/samplecode/Sample_Code/Networking/GetPrimaryMACAddress/GetPrimaryMACAddress.c.htm


Best,


Ken