Getting MAC Addresses

Mark Talluto userev at canelasoftware.com
Fri Oct 5 03:59:49 EDT 2007


On Oct 4, 2007, at 8:43 AM, Ken Ray wrote:

> On Thu, 4 Oct 2007 15:32:34 +0100, David Burgun wrote:
>
>> Hi,
>>
>> How can I get the MAC addresses of all appropriate devices on a
>> system? e.g. if a system has Ethernet and BlueTooth, I want the MAC
>> address of both devices. This has to work on Mac OS X and Windows.
>
> Well, there's a tip about getting the MAC Address here:
>
>   http://www.sonsothunder.com/devres/revolution/tips/env001.htm
>
> Although it is designed for Ethernet, it could easily be adapted for
> BlueTooth, I'd think.



This is from Ken's site slightly modified (windows portion) to look  
for the ethernet mac address.  On windows, the order in which config / 
all provides is based on which device is currently connected to the  
internet.

All you need to do is take out the references to Canela Software and  
put your company name in there.


-Mark Talluto



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 "An error has occurred.  Please contact  
CANELA Software for support."
                 else
                     get matchtext(ifconfigs,"(?s)ether (.*?)  
",retVal)  -- These are spaces on either side of (.*?)
                     if it is false then
                         return "An error has occurred.  Please  
contact your vendor for support."
                     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

                 --FOCUS ON ETHERNET
                 put offset("Ethernet adapter",temp) into tOffsetResult
                 delete char 1 to (tOffsetResult-1) in temp

                 --DO ENGLISH CHECK
                 get matchtext(temp,"Physical Address[\. ]*: ([A- 
Z0-9-]*)",retVal)
                 if retVal is empty then --DO GERMAN CHECK
                     get matchtext(temp,"Physikalische Adresse[\. ]*:  
([A-Z0-9-]*)",retVal)
                 end if
                 if retVal is empty then --DO SPANISH CHECK
                     get matchtext(temp,"Dirección física[\. ]*: ([A- 
Z0-9-]*)",retVal)
                 end if
                 if retVal is empty then --DO FRENCH CHECK
                     get matchtext(temp,"Adresse physique[\. ]*: ([A- 
Z0-9-]*)",retVal)
                 end if
             else
                 return "An error has occurred.  Please contact your  
vendor for support."
             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-Z:]*)",retVal)
             else
                 return "An error has occured.  Please contact your  
vendor for support."
             end if
             break

     end switch
     return retVal
end GetMACAddress


More information about the use-livecode mailing list