我已经实现了这个功能,不过是局域网、2000下,调用iphlpapi.dll中的sendarp函数
function SendARP(DestIP:ipaddr;SrcIP:ipaddr;pMacAddr
ulong;PhyAddrLen
ulong)
WORD;
stdCall; external 'IPHLPAPI.DLL'
其中注意:
type
ipaddr = longint;
pulong = ^u_long;
然后源码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,winsock,iphlpapi;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
procedure getmacbyip(const ipaddress: WideString;
var macaddress, status: OleVariant);
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure Tform1.getmacbyip(const ipaddress: WideString;
var macaddress, status: OleVariant);
var
destip:integer;
pmacaddr
ulong;
addrlen:u_long;
macaddr: array [1..6] of byte;
p
byte;
s:string;
i:integer;
ipstr:string;
begin
IPstr := IPaddress;
DestIP := inet_addr(pchar(IPstr));
pMacAddr := pulong(@MacAddr);
AddrLen := sizeof(MacAddr);
if SendARP(DestIP, 0, pMacAddr, @AddrLen) = 0 then
begin
s := '';
p :=pbyte(pMacAddr);
if ((p<>nil) and (AddrLen>0)) then
begin
for i := 1 to AddrLen do
begin
s := s + IntToHex(p^,2) + '-';
p := Pointer(Integer(p)+SizeOf(Byte));
end;
SetLength(s,Length(s)-1);
end;
end;
macaddress:=s;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
status,macaddr
levariant;
begin
getmacbyip(edit1.Text,macaddr,status);
label1.Caption:=macaddr;
end;
end.
希望能有所帮助.