原理是通过发送ARP包来检测
uses
WinSock function SendARP(const DestIP, SrcIP: Cardinal; pMacAddr: PULONG; var PhyAddrLen: ULONG): DWORD; stdcall;
external 'iphlpapi.dll'; {调用}
var
nMacAddr: array[..] of Byte;
nMacAddrLen: ULONG;
nRet: DWORD;
begin
nMacAddrLen := SizeOf(nMacAddr);
nRet := SendARP(inet_addr(PAnsiChar('192.168.1.1')), , @nMacAddr, nMacAddrLen);
if nRet = then
Memo1.Lines.add('IP: 192.168.1.1 MAC: ' +
Format('%.2x.%.2x.%.2x.%.2x.%.2x.%.2x', [nMacAddr[], nMacAddr[], nMacAddr[], nMacAddr[], nMacAddr[], nMacAddr[]]))
else
Memo1.Lines.add('IP: 192.168.1.1 不在线');
end;