zoukankan      html  css  js  c++  java
  • 取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;
    
    
    
     
  • 相关阅读:
    [UVA100] The 3n + 1 problem.题解
    [SP1] TEST
    LCA【模板】
    [P1000] 超级玛丽游戏.题解
    [P3367]【模板】并查集.题解
    并查集【模板】
    洛谷 P1890 【gcd区间】
    浅谈分块算法经典问题&优化
    Floyd算法详(cha)解
    逆序对
  • 原文地址:https://www.cnblogs.com/westsoft/p/5991631.html
Copyright © 2011-2022 走看看