delphi 實現通過ip地址獲取mac地址 .

function sendarp(ipaddr:ulong;temp:dword;ulmacaddr:pointer;ulmacaddrleng:pointer) : Dword; StdCall;
    External 'Iphlpapi.dll' Name 'SendARP';
function GetMACByIP(const Ip:string):string;
var
  MyIp:ulong;
  MyMac:array[0..5] of byte;
  MyMacLength:ulong;
  ErrCode:integer;
begin
  Myip:=inet_addr(PChar(Ip));
  MyMacLength:=Length(MyMac);
  ErrCode:=SendArp(MyIp,0,@MyMac,@MyMacLength);
  if ErrCode = 0 then
     Result := Format('%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x',[MyMac[0],MyMac[1],MyMac[2],MyMac[3],MyMac[4],MyMac[5]])
  else
     Result := ''; //EorrCode: ErrCode
end;
posted @ 2012-09-20 14:49  马儿快跑  阅读(986)  评论(0编辑  收藏  举报