一段检测IP设备是否在线的代码

原理是通过发送ARP包来检测

uses
    WinSock

function SendARP(const DestIP, SrcIP: Cardinal; pMacAddr: PULONG; var PhyAddrLen: ULONG): DWORD; stdcall;
    external 'iphlpapi.dll';

{调用}
var
    nMacAddr: array[1..6] of Byte;
    nMacAddrLen: ULONG;
  nRet: DWORD;
begin
  nMacAddrLen := SizeOf(nMacAddr);
  nRet := SendARP(inet_addr(PAnsiChar('192.168.1.1')), 0, @nMacAddr, nMacAddrLen);
  if nRet = 0 then
      Memo1.Lines.add('IP: 192.168.1.1 MAC: ' + 
          Format('%.2x.%.2x.%.2x.%.2x.%.2x.%.2x', [nMacAddr[1], nMacAddr[2], nMacAddr[3], nMacAddr[4], nMacAddr[5], nMacAddr[6]]))
  else
      Memo1.Lines.add('IP: 192.168.1.1 不在线');
end;
原文地址:https://www.cnblogs.com/lzl_17948876/p/3327882.html