HanDs
管理员

[Delphi文章] 获取IP地址以及MAC地址绑定 



function GetNetBIOSAddress : string;
var  ncb  : TNCB;
  status  : TAdapterStatus;
  lanenum : TLanaEnum;
    procedure ResetAdapter (num : char);
    begin
      fillchar(ncb,sizeof(ncb),0);
      ncb.ncb_command:=char(NCBRESET);
      ncb.ncb_lana_num:=num;
      Netbios(@ncb);
    end;
var
  i:integer;
  lanNum  : char;
  address : record
             part1 : Longint;
             part2 : Word;
            end absolute status;
begin
  Result:='';
  fillchar(ncb,sizeof(ncb),0);
    ncb.ncb_command:=char(NCBENUM);
    ncb.ncb_buffer:[email protected];
    ncb.ncb_length:=sizeof(lanenum);
  Netbios(@ncb);
  if lanenum.length=#0 then exit;
  lanNum:=lanenum.lana[0];
  ResetAdapter(lanNum);
  fillchar(ncb,sizeof(ncb),0);
    ncb.ncb_command:=char(NCBASTAT);
    ncb.ncb_lana_num:=lanNum;
    ncb.ncb_callname[0]:='*';
    ncb.ncb_buffer:[email protected];
    ncb.ncb_length:=sizeof(status);
  Netbios(@ncb);
  ResetAdapter(lanNum);
  for i:=0 to 5 do
  begin
    result:=result+inttoHex(integer(Status.adapter_address[i]),2);
    if (i<5) then
    result:=result+'-';
  end;
end;


IP地址与MAC地址绑定

procedure TForm1.Button1Click(Sender: TObject);
var command:string;
begin
  panel1.Caption:='IP 地址:'+ IdIPWatch1.LocalIP;
  panel2.Caption:='MAC地址:'+ GetNetBIOSAddress;
  command:='arp -s'+#32+IdIPWatch1.LocalIP+#32+GetNetBIOSAddress;
  WinExec(pchar(command),sw_hide);
end;


学习中请遵守法律法规,本网站内容均来自于互联网,本网站不负担法律责任
获取
#1楼
发帖时间:2016-7-9   |   查看数:0   |   回复数:0
游客组
快速回复