Delphi 获取Mac地址

本文介绍了一种使用Delphi通过调用Windows API来获取计算机MAC地址的方法。该方法利用了RPC库中的UuidCreate函数生成全局唯一标识符,并通过比较特定字节来间接获取MAC地址的后六位。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. function MacAddress: string;
  2. var
  3.   Lib: Cardinal;
  4.   Func: function(GUID: PGUID): Longint; stdcall;
  5.   GUID1, GUID2: TGUID;
  6. begin
  7.   Result := '';
  8.   Lib := LoadLibrary('rpcrt4.dll'); 
  9.   if Lib <> 0 then
  10.   begin
  11.     if Win32Platform <>VER_PLATFORM_WIN32_NT then
  12.       @Func := GetProcAddress(Lib, 'UuidCreate')
  13.       else @Func := GetProcAddress(Lib, 'UuidCreateSequential');
  14.     if Assigned(Func) then
  15.     begin
  16.       if (Func(@GUID1) = 0and
  17.         (Func(@GUID2) = 0and
  18.         (GUID1.D4[2] = GUID2.D4[2]) and
  19.         (GUID1.D4[3] = GUID2.D4[3]) and
  20.         (GUID1.D4[4] = GUID2.D4[4]) and
  21.         (GUID1.D4[5] = GUID2.D4[5]) and
  22.         (GUID1.D4[6] = GUID2.D4[6]) and
  23.         (GUID1.D4[7] = GUID2.D4[7]) then
  24.       begin
  25.         Result :=
  26.          IntToHex(GUID1.D4[2], 2) + '' +
  27.          IntToHex(GUID1.D4[3], 2) + '' +
  28.          IntToHex(GUID1.D4[4], 2) + '' +
  29.          IntToHex(GUID1.D4[5], 2) + '' +
  30.          IntToHex(GUID1.D4[6], 2) + '' +
  31.          IntToHex(GUID1.D4[7], 2);
  32.       end;
  33.     end;
  34.     FreeLibrary(Lib);
  35.   end;
  36. end;
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值