delphi获取MAC地址

2022-11-17 14:33:14 作者:admin

本文整理自网络,侵删。

 获取MAC地址有很多种方法,可以读取注册表,可以读取底层信息等等。本例采用调用系统dll方法获取网卡MAC地址。在该例子的基础上稍加修改就可以用网卡MAC地址进行软件加密。  注意:必须在uses部分加入NB30   演示:

//代码如下: unit Unit1;interfaceuses   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,   Dialogs, StdCtrls, Nb30; type   TForm1 = class(TForm)     Edit_1: TEdit;     Button_1: TButton;     Button_2: TButton;     Label_1: TLabel;     procedure Button_2Click(Sender: TObject);     procedure Button_1Click(Sender: TObject);   private     { Private declarations }   public     { Public declarations }   end;var   Form1: TForm1; implementation {$R *.dfm} //另一种获取方式function GetMACAdress: string; var   NCB: TNCB;   Adapter: TAdapterStatus;   LanEnum: TlanaEnum;   procedure ResetAdapter(num:AnsiChar);     begin       Fillchar(NCB, SizeOf(NCB), 0);       NCB.ncb_command := char(NCBRESET);       NCB.ncb_lana_num := num;       Netbios(@NCB);     end;   var     i:Integer;     LanNum:AnsiChar;     Address:record             Part1:LongInt;             Part2:Word;   end absolute Adapter;   begin     Result    := '';     Fillchar(NCB, SizeOf(NCB), 0);       Ncb.ncb_command  := char(NCBRESET);       Ncb.ncb_buffer :=@LanEnum;       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(NCBRESET);       Ncb.ncb_lana_num :=LanNum;       NCB.ncb_callname[0]:='*';       Ncb.ncb_buffer :=@Adapter;       NCB.ncb_length:=SizeOf(Adapter);     Netbios(@NCB);     ResetAdapter(LanNum);     for i := 0 to 5 do       begin         Result:=Result+IntToHex(Integer(Adapter.adapter_address), 2);         if i<5 then Result:=Result+'-';//返回MAC地址       end; end; //调用函数Function MacAddress: string; var    Lib: Cardinal;    Func: function(GUID: PGUID): Longint; stdcall;    GUID1, GUID2: TGUID; begin    Result := '';    Lib := LoadLibrary('rpcrt4.dll');    if Lib <> 0 then    begin      if Win32Platform <>VER_PLATFORM_WIN32_NT then        @Func := GetProcAddress(Lib, 'UuidCreate')        else @Func := GetProcAddress(Lib, 'UuidCreateSequential');      if Assigned(Func) then      begin        if (Func(@GUID1) = 0) and          (Func(@GUID2) = 0) and          (GUID1.D4[2] = GUID2.D4[2]) and          (GUID1.D4[3] = GUID2.D4[3]) and          (GUID1.D4[4] = GUID2.D4[4]) and          (GUID1.D4[5] = GUID2.D4[5]) and          (GUID1.D4[6] = GUID2.D4[6]) and          (GUID1.D4[7] = GUID2.D4[7]) then        begin          Result :=           IntToHex(GUID1.D4[2], 2) + '-' +           IntToHex(GUID1.D4[3], 2) + '-' +           IntToHex(GUID1.D4[4], 2) + '-' +           IntToHex(GUID1.D4[5], 2) + '-' +           IntToHex(GUID1.D4[6], 2) + '-' +           IntToHex(GUID1.D4[7], 2);        end;      end;      FreeLibrary(Lib);    end; end; //点击获取MAC地址procedure TForm1.Button_1Click(Sender: TObject); begin   Edit_1.Text:=MacAddress; end; //关闭程序procedure TForm1.Button_2Click(Sender: TObject); begin   Close; end;end.

相关阅读 >>

Delphi 通过u盘方式加密

Delphi 取得当前进程占用内存及线程数

Delphi获取flash文件的影片时长,原始尺寸,帧数等信息

Delphi源码一个对字符加密解密的实例

Delphi 使用 lockbox 做加密解密

Delphi中用ado连接加密access数据库

Delphi idtcp下载文件

Delphi xe android判断程序是否在运行

Delphi 取得文件版本

Delphi idhttp下载带清理网络缓存

更多相关阅读请进入《Delphi》频道 >>



在线咨询 拨打电话