How to read MAC address programmatically? lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- dieselnutjob · 2014-04-15 15:18 I have figured out how to read the MAC address(es) of a PC in Linux (from /proc/net/dev or /sys/class/net), and from Windows (Win 32 GetIfTable API call) but I really cannot figure out how to do this in Mac OS X. Does anyone know? ---------------------------------------------------------------------- dieselnutjob · 2014-04-15 15:41 ok I found this https://developer.apple.com/library/mac/samplecode/GetPrimaryMACAddres s/Introduction/Intro.html I haven't figured out yet if I can do this from fpc ---------------------------------------------------------------------- jwdietrich · 2014-04-17 22:10 An (albeit not too elegant) solution could be: Code: [Select]uses   Process, StrUtils; function ExtractMAC(theList: TStringList; theKey: string): string; var   i, j, theLine, thePos: integer; begin   theLine := -1;   for i := 0 to theList.Count - 1 do     begin     j := pos(theKey, theList.Strings[i]);     if j > 0 then       begin         theLine := i;         thePos := j + length(theKey) + 1;       end;     end;   if theLine > -1 then     result := ExtractSubStr(theList.Strings[theLine], thePos, [' ']); end; procedure TForm1.GetaddressButtonClick(Sender: TObject); var   theProcess: TProcess;   theOutput: TStringList; begin   DomainEdit.Text := GetDomainName;   HostEdit.Text := GetHostName;   theProcess := TProcess.Create(nil);   theProcess.Executable := 'ifconfig';   theProcess.Parameters.Add('en0');   theProcess.Options := theProcess.Options + [poWaitOnExit, poUsePipes];   theProcess.Execute;   theOutput := TStringList.Create;   theOutput.LoadFromStream(theProcess.Output);   MAC1Edit.Text := ExtractMAC(theOutput, 'ether');   theOutput.Free;   theProcess.Free;   theProcess := TProcess.Create(nil);   theProcess.Executable := 'ifconfig';   theProcess.Parameters.Add('en1');   theProcess.Options := theProcess.Options + [poWaitOnExit, poUsePipes];   theProcess.Execute;   theOutput := TStringList.Create;   theOutput.LoadFromStream(theProcess.Output);   MAC2Edit.Text := ExtractMAC(theOutput, 'ether');   theOutput.Free;   theProcess.Free;   theProcess := TProcess.Create(nil);   theProcess.Executable := 'ifconfig';   theProcess.Parameters.Add('fw0');   theProcess.Options := theProcess.Options + [poWaitOnExit, poUsePipes];   theProcess.Execute;   theOutput := TStringList.Create;   theOutput.LoadFromStream(theProcess.Output);   MAC3Edit.Text := ExtractMAC(theOutput, 'lladdr');   theOutput.Free;   theProcess.Free; end;                    This procedure fills the contents of three edits fields with the MAC addresses of two ethernet interfaces (en0 and en1) and one firewire interface (fw0). You may want to change the code as required. See also the attached demo project for reference.