Vaya, no se mostró bien a ver ahora
Código Delphi
[-]unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, winsock,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
private
public
end;
type
PULONG = ^ULONG;
var
Form1: TForm1;
implementation
{$R *.dfm}
function SendARP(DestIP,SrcIP: in_addr; pMacAddr,PhyAddrLen: PULONG): DWORD;
stdcall; external 'iphlpapi.dll' name 'SendARP';
function ObtenerMAC(IP: Ansistring): Ansistring;
var
i: Integer;
dwRetVal: DWORD;
DestIp, SrcIp: in_addr;
MacAddr: array[0..1] of ULONG;
PhysAddrLen: ULONG;
PhysAddr: PByte;
begin
DestIp.S_addr:= 0;
SrcIp.S_addr:= 0;
PhysAddrLen:= 6;
DestIp.S_addr:= inet_addr(PAnsiChar(AnsiString(IP)));
dwRetVal:= SendARP(DestIp, SrcIp, @MacAddr, @PhysAddrLen);
Result:= EmptyStr;
if dwRetVal = NO_ERROR then
begin
PhysAddr:= PByte(@MacAddr);
for i := 1 to Sizeof(MacAddr)-2 do
begin
if Result= EmptyStr then
Result:= IntToHex(PhysAddr^,2)
else
Result:= Result + '-' + IntToHex(PhysAddr^,2);
inc(PhysAddr);
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
label1.Caption:=ObtenerMAC(edit1.Text);
end;
end.