An expanded version which should work for both MacOS X (tested with El Capitan) and Windows (tested with Windows 10), Windows users will see a shell window popup briefly.
function Ping(Host:string):boolean;
var s : ansistring;
const PingCount = '2'; // number of pings
PingTimeout = '2'; // timout for each ping
begin
s:='';
{$IFDEF Darwin}
RunCommand('/sbin/ping',['-c '+PingCount,'-t '+PingTimeout,'-q',Host],s);
{$ENDIF}
{$IFDEF Windows}
RunCommand('ping.exe',['-n ',PingCount,'-w ',PingTimeout,Host],s);
{$ENDIF}
Result := (pos('100.0% packet loss',S)=0) and (pos('100% packet loss',S)=0) and (pos('100% loss',S)=0);
end;
function GetMACAddress(Host:string):string;
var s : ansistring;
MacAddress, MacNo:string;
Counter:integer;
ArpExe:string;
begin
if ping(Host) then
begin
s:='';
{$IFDEF Darwin}
RunCommand('/usr/sbin/arp',[Host],s);
{$ENDIF}
{$IFDEF Windows}
RunCommand('arp.exe',['-a',Host],s);
{$ENDIF}
{$IFDEF Darwin}
if (pos(':',s)=0) or (pos('(incomplete)',s)>0) or (pos(' -- no entry',s)>0) then
{$ENDIF}
{$IFDEF Windows}
if (pos('Physical Address',s)=0) or (pos('No ARP Entries Found',s)>0) then
{$ENDIF}
Result := BlankMACAddress
else
begin
{$IFDEF Darwin}
s := copy(s,pos(' at ',s)+4,Length(s));
s := copy(s,0,pos(' on ',s)-1);
MacAddress:='';
for Counter:=1 to 5 do
begin
MacNo:=Copy(S, 0, pos(':',S)-1);
s:=Copy(s,pos(':',S)+1,Length(S));
if Length(MacNo)=1 then MacNo:='0'+MacNo;
MacAddress:=MacAddress+MacNo+':';
end;
MacAddress:=MacAddress+s;
{$ENDIF}
{$IFDEF Windows}
// Windows stuff here
s:=Copy(s,pos(Host,s)+Length(Host),Length(s));
s:=trim(s);
MacAddress:='';
for Counter:=1 to 5 do
begin
MacNo:=Copy(S, 0, pos('-',S)-1);
s:=Copy(s,pos('-',S)+1,Length(S));
if Length(MacNo)=1 then MacNo:='0'+MacNo;
MacAddress:=MacAddress+MacNo+':';
end;
MacAddress:=MacAddress+Copy(s,0,2);
{$ENDIF}
Result:=UpperCase(MacAddress);
end;
end
else
Result:=BlankMACAddress;
end;