通过IP取得mac地址

unit mac;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    lbl1: TLabel;
    lbl2: TLabel;
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses
WinSock;

Function sendarp(ipaddr:ulong;
temp:dword;
ulmacaddr:pointer;
ulmacaddrleng:pointer) : DWord; StdCall; External 'Iphlpapi.dll' Name 'SendARP';


procedure TForm1.Button1Click(Sender: TObject);
var
  myip, CLONEip:ulong;
  mymac:array[0..5] of byte;
  mymaclength:ulong;
  r:integer;
  TEMP: aNSIsTRING;
begin
  lbl2.Caption := '0';
  TEMP := Edit1.Text;
  CLONEip:=inet_addr(PAnsiChar(TEMP));
//  myip:=inet_addr(PAnsiChar('192.168.1.100'));
  mymaclength:=length(mymac);
  r:=sendarp(CLONEip,0,@mymac,@mymaclength);
  lbl1.caption:='errorcode:'+inttostr(r);
  lbl2.caption:=format('%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x',[mymac[0],mymac[1],mymac[2],mymac[3],mymac[4],mymac[5]]);
end;

end.

posted @ 2013-02-24 15:41  神码都在云端  阅读(467)  评论(0编辑  收藏  举报