Arsip: Membaca MAC-Address


by delphi in Articles more 19 years ago 2131
Ingin tau cara membaca MAC-Address?
berikut ini petikan kode-nya
Type
TMACAddress = Array[0..5] Of Byte;
PMACAddress = ^TMACAddress;
Function GetMACAddress(AdapterNumber: Byte; MACAddress: PMACAddress): Byte;
Var
tmpNCB: PNCB;
AdapterStatus: PAdapterStatus;
begin
New(tmpNCB);
ZeroMemory(tmpNCB, SizeOf(TNCB));
tmpNCB.ncb_length := SizeOf(TAdapterStatus) + 255  SizeOf(TNameBuffer);
GetMem(AdapterStatus, tmpNCB.ncb_length);
Try
With tmpNCB^ Do
Begin
ZeroMemory(MACAddress, SizeOf(TMACAddress));
ncb_buffer := PChar(AdapterStatus);
ncb_callname := '  ' +#0;
ncb_lana_num := Char(AdapterNumber);
ncb_command := Char(NCBASTAT);
NetBios(tmpNCB);
Result := Byte(ncb_cmd_cplt);
If Result = NRC_GOODRET Then
MoveMemory(MACAddress, AdapterStatus, SizeOf(TMACAddress));
End;
Finally
FreeMem(AdapterStatus);
Dispose(tmpNCB);
End;
End;
Function GetMACAddressAsString(AdapterNumber: Byte): String;
Var
tmpMACAddress: TMACAddress;
Begin
If Win32Platform = VER_PLATFORM_WIN32_NT Then
If ResetLANAdapter(AdapterNumber) <> NRC_GOODRET Then
Begin
Result := '??-??-??-??-??-??';
Exit;
End;
If GetMACAddress(AdapterNumber, @tmpMACAddress) = NRC_GOODRET Then
Result := Format('%2.2x-%2.2x-%2.2x-%2.2x-%2.2x-%2.2x',
[tmpMACAddress[0], tmpMACAddress[1], tmpMACAddress[2], tmpMACAddress[3],
tmpMACAddress[4], tmpMACAddress[5]])
Else
Result := '??-??-??-??-??-??';
End;

Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com