KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How to retrieve all MAC addresses for a machine running Mac OS X
PRODUCT: 4D | VERSION: 11.5 | PLATFORM: Mac OS X
Published On: April 29, 2010

LAUNCH EXTERNAL PROCESS and Match regex commands can be used to retrieve all MAC addresses available on the machine that runs 4D v11 SQL. The following code snipped retrieves all MAC addresses from any Mac OS X machine and populates them into an array:

ARRAY LONGINT($posFound_a;0)
ARRAY LONGINT($lengthFound_a;0)
ARRAY TEXT($foundMacs_a;0)
C_LONGINT($start)
C_BOOLEAN($found)
C_TEXT($substr)
C_TEXT($pattern)
C_TEXT(inputVal; outputVal)

inputVal:=" "
LAUNCH EXTERNAL PROCESS("/sbin/ifconfig -a";inputVal;outputVal)
$pattern:="([0-9a-f]{1,2}:){5,13}[0-9a-f]{1,2}"
$start:=1

Repeat
  $found:=Match regex($pattern;outputVal;$start;$posFound_a;$lengthFound_a)
  If($found)
    $start:=$posFound_a{0} + $lengthFound_a{0}
    $substr:=Substring(outputVal;$posFound_a{0};$lengthFound_a{0})
    APPEND TO ARRAY($foundMacs_a;$substr)
  End if
Until(Not($found))


After running the above code $foundMacs_a array will be populated with all MAC addresses.