l i v e c o d e

Getting the MAC Address
Mac OS 9 Mac OS X Windows Linux

This code will work to return the MAC Address of the current computer. The different ways of accessing this is noted below:
You can customize this code for your own purposes, or use it as is.
on mouseUp
  put GetMACAddress() into theMACAddress
end mouseUp

function GetMACAddress local retVal switch (the platform) case "MacOS" set the itemDel to "." if item 1 of the systemVersion < 10 then set the directory to specialFolderPath("apple") put "tell application" && quote & "Apple System Profiler" & \ quote & cr & "get appletalk address" & cr & "end tell" into getMACScript put "tell application" && quote & "Apple System Profiler" & \ quote & cr & "close window" && quote & "Apple System Profiler" & quote & \ cr & "end tell" into quitASPScript do getMACScript as AppleScript put the result into retVal do quitASPScript as AppleScript replace "{" with "" in retVal replace "}" with "" in retVal replace quote with "" in retVal else put shell("/sbin/ifconfig en0") into ifConfigs if char 1 to 4 of ifConfigs = "zsh:" then return "Error retrieving interface configuration." else get matchText(ifconfigs,"(?s)ether (.*?) ",retVal) -- These are spaces on either side of (.*?) if it is false then return "Error retrieving MAC address." end if end if end if break case "Win32" put (there is a file (specialFolderPath("system") & "/IPCONFIG.EXE")) into winExists put (there is a file (specialFolderPath("system") & "/SYSTEM32/IPCONFIG.EXE")) into sys32Exists if winExists or sys32Exists then set the hideConsoleWindows to true put shell("ipconfig /all") into temp get matchText(temp,"Physical Address[\. ]*: ([A-Z0-9-]*)",retVal) else return "IPCONFIG not found" end if break case "Linux" if there is a file("/sbin/ifconfig") then put shell("/sbin/ifconfig") into temp get matchText(temp,"HWaddr[* ]([0-9A-Za-z:]*)",retVal) else return "An error has occured." end if break end switch return retVal end GetMACAddress

Posted 7/16/2002 by Ken Ray
Modified 11/12/2002 by Ken Ray (genericized matchText function call)
Modified 11/6/2002 by Mark Talluto (systemversion comparison)
Modified 10/9/2004 by Mark Talluto (Linux version) Modified 1/24/2011 by Warren Samples (Linux version)


 Print this tip

News and Rumors Products Services Developer Resources Contact STS About STS