Detect your MAC address using NetBIOS in Delphi

program GetMAC;
uses
Dialogs, SysUtils, nb30;
function GetMACAddress(PCName: string) : string;
type
TASTAT = packed record
adapt: nb30.TADAPTERSTATUS;
NameBuff: array [0..30] of TNAMEBUFFER;
end;
var
NCB: TNCB;
Tmp: String;
pASTAT: Pointer;
AST: TASTAT;
begin
// The IBM NetBIOS 3.0 specifications defines four basic
// NetBIOS environments under the NCBRESET command. Win32
// follows the OS/2 Dynamic Link Routine (DLR) environment.
// This means that the first NCB issued by an application
// must be a NCBRESET, with the exception of NCBENUM.
// The Windows NT implementation differs from the IBM
// NetBIOS 3.0 specifications in the NCB_CALLNAME field.
FillChar(NCB, SizeOf(NCB), 0);
NCB.ncb_command := Chr(NCBRESET);
NetBios(@NCB);
// To get the Media Access Control (MAC) address for an
// ethernet adapter programmatically, use the Netbios()
// NCBASTAT command and provide a "*" as the name in the
// NCB.ncb_CallName field (in a 16-chr string).
// NCB.ncb_callname = "* "
FillChar(NCB, SizeOf(NCB), 0);
FillChar(NCB.ncb_callname[0], 16, ' ');
Move(PCName[1], NCB.ncb_callname[0], Length(PCName));
NCB.ncb_command := Chr(NCBASTAT);
// For machines with multiple network adapters you need to
// enumerate the LANA numbers and perform the NCBASTAT
// command on each. Even when you have a single network
// adapter, it is a good idea to enumerate valid LANA numbers
// first and perform the NCBASTAT on one of the valid LANA
// numbers. It is considered bad programming to hardcode the
// LANA number to 0 (see the comments section below).
NCB.ncb_lana_num := #0;
NCB.ncb_length := SizeOf(AST);
GetMem(pASTAT, NCB.ncb_length);
if pASTAT=nil then
begin
result := 'memory allocation failed!';
exit;
end;
NCB.ncb_buffer := pASTAT;
NetBios(@NCB);
Move(NCB.ncb_buffer, AST, SizeOf(AST));
with AST.adapt do
Tmp := Format('%.2x-%.2x-%.2x-%.2x-%.2x-%.2x',
[ord(adapter_address[0]), ord(adapter_address[1]), ord(adapter_address[2]),
ord(adapter_address[3]), ord(adapter_address[4]), ord(adapter_address[5])]);
FreeMem(pASTAT);
Result := Tmp;
end;
begin
ShowMessage(GetMACAddress('*'));
end.