zoukankan      html  css  js  c++  java
  • Delphi获取本机的MAC地址

    Delphi获取本机的MAC地址:


    uses
      NB30;


    function GetAdaPterInfo(lana: Char): string;
    var
      Adapter: TAdapterStatus;
      NCB: TNCB;
    begin
      FillChar(NCB,Sizeof(NCB),0);
      NCB.ncb_command := Char(NCBRESET);
      NCB.ncb_lana_num := Lana;
      if Netbios(@NCB) <> Char(NRC_GOODRET) then
      begin
        Result := 'mac not found';
        exit;
      end;
      FillChar(NCB,Sizeof(NCB),0);
      NCB.ncb_command := Char(NCBASTAT);
      NCB.ncb_lana_num := Lana;
      NCB.ncb_callname := '*';

      FillChar(Adapter,Sizeof(Adapter),0);
      NCB.ncb_buffer := @Adapter;
      NCB.ncb_length := Sizeof(Adapter);
      if Netbios(@NCB) <> Char(NRC_GOODRET) then
      begin
        result :='mac not found';
        Exit;
      end;
      Result := 
        IntToHex(Byte(Adapter.adapter_address[0]), 2) + '_'+
        IntToHex(Byte(Adapter.adapter_address[1]), 2) + '_'+
        IntToHex(Byte(Adapter.adapter_address[2]), 2) + '_'+
        IntToHex(Byte(Adapter.adapter_address[3]), 2) + '_'+
        IntToHex(Byte(Adapter.adapter_address[4]), 2) + '_'+
        IntToHex(Byte(Adapter.adapter_address[5]), 2) ;
    end;


    function GetMACAddress: string;
    var
      AdapterList: TLanaEnum;
      NCB: TNCB;
    begin
      FillChar(NCB,Sizeof(NCB),0);
      NCB.ncb_command := Char(NCBENUM);
      NCB.ncb_buffer := @AdapterList;
      NCB.ncb_length := SizeOf(AdapterList);
      Netbios(@NCB);
      if Byte(AdapterList.length) > 0 then
        Result := GetAdapterInfo(AdapterList.lana[0])
      else
        Result := 'mac not found';
    end;


    调用: s:= GetMACAddress;

  • 相关阅读:
    解决Flask使用pymysql驱动的Warning: (1366, "Incorrect string value: '\xD6\xD0\xB9\xFA\xB1\xEA...'
    java中的抽象类
    java中的接口
    java中获取数组中的最大值
    java中的面向对象
    java中的数组
    java中的方法
    java中的流程控制结构
    java中的运算符
    java中的类型转换
  • 原文地址:https://www.cnblogs.com/xtfnpgy/p/9285388.html
Copyright © 2011-2022 走看看