帮我看安康内下面的程序:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,Winsock,Registry,NB30;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementationtype
PMACAddress=^TMACAddress;
TMACAddress=array[0..5] of Byte;
var MACAddress:TMACAddress;
{$R *.dfm}
function GetLocalTime : AnsiString;
var
stSystemTime : TSystemTime;
begin
Windows.GetLocalTime( stSystemTime );
Result := DateTimeToStr( SystemTimeToDateTime( stSystemTime ) );
end;
//以下函数用以获得网卡地址
function GetMACAddress(LanaNum:Byte; MACAddress:PMACAddress):Byte;
var
AdapterStatus:PAdapterStatus;
StatNCB:PNCB;
begin
New(StatNCB);
ZeroMemory(StatNCB,SizeOf(TNCB));
StatNCB.ncb_length:=SizeOf(TAdapterStatus)+255*SizeOf(TNameBuffer);
GetMem(AdapterStatus,StatNCB.ncb_length);
try
with StatNCB^ do
begin
ZeroMemory(MACAddress,SizeOf(TMACAddress));
ncb_buffer:=PChar(AdapterStatus);
ncb_callname:='*'+#0;
ncb_lana_num:=Char(LanaNum);
ncb_command:=Char(NCBASTAT);
NetBios(StatNCB);
Result:=Byte(ncb_cmd_cplt);
if Result=NRC_GOODRET then
MoveMemory(MACAddress,AdapterStatus,SizeOf(TMACAddress));
end;
finally
FreeMem(AdapterStatus);
Dispose(StatNCB);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
if GetLocalTime='' then
label1.Caption:='未取得系统时间'
else
label1.caption:='你的系统时间是:'+GetLocalTime;
label2.caption:='你的网卡地址是:'+Format('%2.2x-%2.2x-%2.2x-%2.2x-%2.2x-%2.2x',[MACAddress[0], MACAddress[1], MACAddress[2],MACAddress[3], MACAddress[4], MACAddress[5]]);
end;
end.
我能运行,可以得到本地时间,但网卡地址全是00.00.00.00.00
是怎么回事啊???
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,Winsock,Registry,NB30;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementationtype
PMACAddress=^TMACAddress;
TMACAddress=array[0..5] of Byte;
var MACAddress:TMACAddress;
{$R *.dfm}
function GetLocalTime : AnsiString;
var
stSystemTime : TSystemTime;
begin
Windows.GetLocalTime( stSystemTime );
Result := DateTimeToStr( SystemTimeToDateTime( stSystemTime ) );
end;
//以下函数用以获得网卡地址
function GetMACAddress(LanaNum:Byte; MACAddress:PMACAddress):Byte;
var
AdapterStatus:PAdapterStatus;
StatNCB:PNCB;
begin
New(StatNCB);
ZeroMemory(StatNCB,SizeOf(TNCB));
StatNCB.ncb_length:=SizeOf(TAdapterStatus)+255*SizeOf(TNameBuffer);
GetMem(AdapterStatus,StatNCB.ncb_length);
try
with StatNCB^ do
begin
ZeroMemory(MACAddress,SizeOf(TMACAddress));
ncb_buffer:=PChar(AdapterStatus);
ncb_callname:='*'+#0;
ncb_lana_num:=Char(LanaNum);
ncb_command:=Char(NCBASTAT);
NetBios(StatNCB);
Result:=Byte(ncb_cmd_cplt);
if Result=NRC_GOODRET then
MoveMemory(MACAddress,AdapterStatus,SizeOf(TMACAddress));
end;
finally
FreeMem(AdapterStatus);
Dispose(StatNCB);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
if GetLocalTime='' then
label1.Caption:='未取得系统时间'
else
label1.caption:='你的系统时间是:'+GetLocalTime;
label2.caption:='你的网卡地址是:'+Format('%2.2x-%2.2x-%2.2x-%2.2x-%2.2x-%2.2x',[MACAddress[0], MACAddress[1], MACAddress[2],MACAddress[3], MACAddress[4], MACAddress[5]]);
end;
end.
我能运行,可以得到本地时间,但网卡地址全是00.00.00.00.00
是怎么回事啊???
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,Winsock,Registry,NB30, StdCtrls;type
TForm1 = class(TForm)
Label1: TLabel;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation
type
TNBLanaResources = (lrAlloc, lrFree);
type
PMACAddress = ^TMACAddress;
TMACAddress = array[0..5] of Byte;
type
TGate = record
Off2,op,seg,off1:WORD;
end;
LONGDWORD = INT64;
{$R *.dfm}
//以下函数用以获得网卡地址。
function GetMACAddress(LanaNum: Byte; MACAddress: PMACAddress): Byte;
var
AdapterStatus: PAdapterStatus;
StatNCB: PNCB;
begin
New(StatNCB);
ZeroMemory(StatNCB, SizeOf(TNCB));
StatNCB.ncb_length := SizeOf(TAdapterStatus) + 255 * SizeOf(TNameBuffer);
GetMem(AdapterStatus, StatNCB.ncb_length);
try
with StatNCB^ do
begin
ZeroMemory(MACAddress, SizeOf(TMACAddress));
ncb_buffer := PChar(AdapterStatus);
ncb_callname := '* ' + #0;
ncb_lana_num := Char(LanaNum);
ncb_command := Char(NCBASTAT);
NetBios(StatNCB);
Result := Byte(ncb_cmd_cplt);
if Result = NRC_GOODRET then
MoveMemory(MACAddress, AdapterStatus, SizeOf(TMACAddress));
end;
finally
FreeMem(AdapterStatus);
Dispose(StatNCB);
end;
end;
function GetLanaEnum(LanaEnum: PLanaEnum): Byte;
var
LanaEnumNCB: PNCB;
begin
New(LanaEnumNCB);
ZeroMemory(LanaEnumNCB, SizeOf(TNCB));
try
with LanaEnumNCB^ do
begin
ncb_buffer := PChar(LanaEnum);
ncb_length := SizeOf(TLanaEnum);
ncb_command := Char(NCBENUM);
NetBios(LanaEnumNCB);
Result := Byte(ncb_cmd_cplt);
end;
finally
Dispose(LanaEnumNCB);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
MACAddress: PMACAddress;
RetCode: Byte;
begin
New(MACAddress);
try
RetCode := GetMACAddress(0, MACAddress);
if RetCode = NRC_GOODRET then
begin
label1.caption := '你的网卡地址是:'+Format('%2.2x-%2.2x-%2.2x-%2.2x-%2.2x-%2.2x',
[MACAddress[0], MACAddress[1], MACAddress[2],
MACAddress[3], MACAddress[4], MACAddress[5]]);
end;
finally
Dispose(MACAddress);
end;
end;
end.
var
NCB: PNCB;
Adapter: PAdapterStatus; URetCode: PChar;
RetCode: char;
I: integer;
Lenum: PlanaEnum;
_SystemID: string;
TMPSTR: string;
begin
Result := '';
_SystemID := '';
Getmem(NCB, SizeOf(TNCB));
Fillchar(NCB^, SizeOf(TNCB), 0); Getmem(Lenum, SizeOf(TLanaEnum));
Fillchar(Lenum^, SizeOf(TLanaEnum), 0); Getmem(Adapter, SizeOf(TAdapterStatus));
Fillchar(Adapter^, SizeOf(TAdapterStatus), 0); Lenum.Length := chr(0);
NCB.ncb_command := chr(NCBENUM);
NCB.ncb_buffer := Pointer(Lenum);
NCB.ncb_length := SizeOf(Lenum);
RetCode := Netbios(NCB); i := 0;
repeat
Fillchar(NCB^, SizeOf(TNCB), 0);
Ncb.ncb_command := chr(NCBRESET);
Ncb.ncb_lana_num := lenum.lana[I];
RetCode := Netbios(Ncb); Fillchar(NCB^, SizeOf(TNCB), 0);
Ncb.ncb_command := chr(NCBASTAT);
Ncb.ncb_lana_num := lenum.lana[I];
// Must be 16
Ncb.ncb_callname := '* '; Ncb.ncb_buffer := Pointer(Adapter); Ncb.ncb_length := SizeOf(TAdapterStatus);
RetCode := Netbios(Ncb);
//---- calc _systemId from mac-address[2-5] XOR mac-address[1]...
if (RetCode = chr(0)) or (RetCode = chr(6)) then
begin
_SystemId := IntToHex(Ord(Adapter.adapter_address[0]), 2) + '-' +
IntToHex(Ord(Adapter.adapter_address[1]), 2) + '-' +
IntToHex(Ord(Adapter.adapter_address[2]), 2) + '-' +
IntToHex(Ord(Adapter.adapter_address[3]), 2) + '-' +
IntToHex(Ord(Adapter.adapter_address[4]), 2) + '-' +
IntToHex(Ord(Adapter.adapter_address[5]), 2);
end;
Inc(i);
until (I >= Ord(Lenum.Length)) or (_SystemID <> '00-00-00-00-00-00');
FreeMem(NCB);
FreeMem(Adapter);
FreeMem(Lenum);
GetMacAdress := _SystemID;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
label1.Caption := GetMACAdress;
end;