取Mac地址

uses Nb30;

//一般用默认的 0 就可以了
function GetMacAddress(const Index:Integer =0):string;
var
   ncb : TNCB;                {NetBios控制块}
   AdapterS : TAdapterStatus; {网卡状态结构}
   LanaNum : TLanaeNum;       {Netbios Lana}
   i : Integer;
   rc : Char;                 {NetBios的返回代码}
   str : String;
begin
   Result := '';
   try
      ZeroMemory(@ncb, SizeOf(ncb));   {NetBios控制块清零}
      ncb.ncb_command := chr(NCBENUM); {ENUM}
      rc := NetBios(@ncb);             {取返回代码}

      ncb.ncb_buffer := @LanaNum;      {再一次处理ENUM命令}
      ncb.ncb_length := SizeOf(LanaNum);
      rc := NetBios(@ncb);             {取返回代码}

      if Ord(rc)<>0 then Exit;

      ZeroMemory(@ncb, SizeOf(ncb));   {NetBios控制块清零}
      ncb.ncb_command := chr(NCBRESET);
      ncb.ncb_lana_num := LanaNum.lana[index];
      rc := NetBios(@ncb);
      if ord(rc)<>0 then Exit;

      ZeroMemory(@ncb, SizeOf(ncb));   {取网卡的状态}
      ncb.ncb_command := chr(NCBASTAT);
      ncb.ncb_lana_num := LanaNum.lana[index];
      StrPCopy(ncb.ncb_callname,'*');
      ncb.ncb_buffer := @AdapterS;
      ncb.ncb_length := SizeOf(AdapterS);
      rc := NetBios(@ncb);

      str := '';                       {将MAC地址转换成字符串}
      for i:=0 to 5 do
         str := str + IntToHex(Integer(AdapterS.adapter_address[i]),2);
      
      Result := str;
      if Result <>'' then
      begin
        Result :=Copy(Result ,1,2)+'-'+Copy(Result ,3,2) +'-'+Copy(Result ,5,2) +'-'+Copy(Result ,7,2)  +'-'+Copy(Result ,9,2)+'-' +Copy(Result ,11,2)
      end;
   finally
   end;
end;


 
原文地址:https://www.cnblogs.com/westsoft/p/5991631.html