就是这段代码啦。MS的专家,请问这样得到的mac地址正确吗?
function GetMacADDR(IPstr:string):string;
label Fend;
var
DestIP:IPAddr;
pMacAddr: PULong;
AddrLen: ULong;
MacAddr: array[0..5] of byte;
p: PByte;
s: string;
i: integer;
SendARP:PSendARP;
HM:Thandle;
begin
Result:='';
hm := loadlibrary('iphlpapi.dll');
if hm = 0 then goto Fend;
SendARP := getprocaddress(hm, 'SendARP');
if @SendARP=nil then goto Fend ;
DestIP := inet_addr(PChar(IPstr));
pMacAddr := @MacAddr[0];
AddrLen := SizeOf(MacAddr);
SendARP(DestIP, 0, pMacAddr, AddrLen);
p := PByte(pMacAddr);
if Assigned(p) and (AddrLen>0) then
for i := 0 to AddrLen-1 do
begin
s := s + IntToHex(p^,2) + '-';
Inc(p);
end;
SetLength(s, length(s)-1);
Result:=s;
Fend:
FreeLibrary(hm);
end;