【发布时间】:2010-07-17 03:55:04
【问题描述】:
可能的重复:
Getting Machine’s MAC Address — Good Solution?
How do I get the MAC address of a network card using Delphi?
我使用 MAC 地址作为硬件 ID 进行保护(当然我已经加密了这些数据) 我正在使用下面的代码来获取用户计算机上的 MAC 地址
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
@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;
end;
end;
以上代码在 Windows XP 上完美运行 但它在windows7中给出不同的值,每次计算机重新命名后值都会改变:( 是否有机会获得恒定的 MAC 地址(除非用户更改了他的 MAC 地址) 还是有什么好的代码可以在所有操作系统上检索常量数据?
提前致谢
【问题讨论】:
-
是什么让您认为this code 检索了您计算机的 MAC 地址?
-
确认!该函数不返回 MAC 地址。它返回一个有时恰好包含 MAC 地址的值。
标签: windows delphi network-programming