W
wonderxin
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,WinSock;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure GetMacAddrFromIP(const IP: String
var Mac: String);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
type
ipaddr = longint;
pulong = ^u_long;
function SendARP(DestIP: ipaddr
SrcIP: ipaddr
pMacAddr: pulong;
PhyAddrLen: pulong): DWORD
stdcall
external 'IPHLPAPI.DLL'
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
var mac:string;
begin
self.GetMacAddrFromIP('192.168.0.1',mac);
self.Caption:=mac;
end;
procedure TForm1.GetMacAddrFromIP(const IP: String;
var Mac: String);
var
DestIP: integer;
pmacaddr: pulong;
addrlen: u_long;
macaddr: array[1..6] of byte;
p: pbyte;
i: integer;
begin
DestIP := inet_addr(pchar(IP))
//目标机器的IP地址
pMacAddr := pulong(@MacAddr);
AddrLen := sizeof(MacAddr);
Mac := '';
if SendARP(DestIP, 0, pMacAddr, @AddrLen) = 0 then
begin
p := pbyte(pMacAddr);
if ((p <> nil) and (AddrLen > 0)) then
begin
for i := 1 to AddrLen do
begin
Mac := Mac + IntToHex(p^, 2) + '-';
p := Pointer(Integer(p) + SizeOf(Byte));
end;
SetLength(Mac, Length(Mac) - 1);
end;
end;
end;
end.
注意我想在网页中根据输入的ip地址得到mac地址,还有其他更好的方法吗?谢谢
还有我用的是asp.net,不知道会.net的朋友有没有办法在.net中直接实现?
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,WinSock;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure GetMacAddrFromIP(const IP: String
var Mac: String);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
type
ipaddr = longint;
pulong = ^u_long;
function SendARP(DestIP: ipaddr
SrcIP: ipaddr
pMacAddr: pulong;
PhyAddrLen: pulong): DWORD
stdcall
external 'IPHLPAPI.DLL'
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
var mac:string;
begin
self.GetMacAddrFromIP('192.168.0.1',mac);
self.Caption:=mac;
end;
procedure TForm1.GetMacAddrFromIP(const IP: String;
var Mac: String);
var
DestIP: integer;
pmacaddr: pulong;
addrlen: u_long;
macaddr: array[1..6] of byte;
p: pbyte;
i: integer;
begin
DestIP := inet_addr(pchar(IP))
//目标机器的IP地址
pMacAddr := pulong(@MacAddr);
AddrLen := sizeof(MacAddr);
Mac := '';
if SendARP(DestIP, 0, pMacAddr, @AddrLen) = 0 then
begin
p := pbyte(pMacAddr);
if ((p <> nil) and (AddrLen > 0)) then
begin
for i := 1 to AddrLen do
begin
Mac := Mac + IntToHex(p^, 2) + '-';
p := Pointer(Integer(p) + SizeOf(Byte));
end;
SetLength(Mac, Length(Mac) - 1);
end;
end;
end;
end.
注意我想在网页中根据输入的ip地址得到mac地址,还有其他更好的方法吗?谢谢
还有我用的是asp.net,不知道会.net的朋友有没有办法在.net中直接实现?