KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How to retrieve all MAC addresses for a Windows machine
PRODUCT: 4D | VERSION: 11.6 | PLATFORM: Win
Published On: April 22, 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 Windows OS and populates them into an array:

ARRAY LONGINT($pos_Found_a;0)
ARRAY LONGINT($length_Found_a;0)
ARRAY TEXT(foundMacs_at;0)
C_LONGINT($start)
C_BOOLEAN($found)
C_TEXT($substr)
C_TEXT(inputVar;outputVar)
C_TEXT($search)

inputVar:=""
SET ENVIRONMENT VARIABLE("_4D_OPTION_HIDE_CONSOLE";"true")
LAUNCH EXTERNAL PROCESS("cmd.exe /C ipconfig /ALL";inputVar;outputVar)
$search:="([0-9A-F]{2}-){5,13}[0-9A-F]{2}"
$start:=1

Repeat
  $found:=Match regex($search;outputVar;$start;$pos_Found_a;$length_Found_a)
  If ($found)
    $start:=$pos_Found_a{0}+$length_Found_a{0}
    $substr:=Substring(outputVar;$pos_Found_a{0};$length_Found_a{0})
    APPEND TO ARRAY(foundMacs_at;$substr)
  End if
Until (Not($found))


After running the above code, the foundMacs_at array will be populated with all MAC addresses.