uses
Windows,SysUtils, Winsock;
type
PARP=function (const DestIP, SrcIP:Cardinal;PMacAddr :PULong; var PhyAddrLen: ULong):dword;stdcall;
function GetMacADDR(IPstr:string):string ;
implementation
function GetMacADDR(IPstr:string):string;
var
DestIP:Cardinal;
pMacAddr: PULong;
AddrLen: ULong;
MacAddr: array[0..5] of byte;
p: PByte;
s: string;
i: integer;
ARP:PARP;
H:Thandle;
begin
Result:='';
h := loadlibrary('iphlpapi.dll');
if hm = 0 then goto Fend;
SendARP := getprocaddress(h, 'ARP');
if @SendARP=nil then
begin
FreeLibrary(hm);
exit;
end;
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;
FreeLibrary(hm);
end;
Windows,SysUtils, Winsock;
type
PARP=function (const DestIP, SrcIP:Cardinal;PMacAddr :PULong; var PhyAddrLen: ULong):dword;stdcall;
function GetMacADDR(IPstr:string):string ;
implementation
function GetMacADDR(IPstr:string):string;
var
DestIP:Cardinal;
pMacAddr: PULong;
AddrLen: ULong;
MacAddr: array[0..5] of byte;
p: PByte;
s: string;
i: integer;
ARP:PARP;
H:Thandle;
begin
Result:='';
h := loadlibrary('iphlpapi.dll');
if hm = 0 then goto Fend;
SendARP := getprocaddress(h, 'ARP');
if @SendARP=nil then
begin
FreeLibrary(hm);
exit;
end;
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;
FreeLibrary(hm);
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货