// Pleace notice, I called the Lan Adapters within a function Lana
// Outside a function I named them Adapter
FUNCTION GetMacAddress(AdapterID : Integer) :
String;
TYPE
TAdapterStatusA =
record
Adapt : TAdapterStatus;
NameBuff :
array[0..30]
of TNameBuffer;
end;
VAR
NCB :TNCB;
//Network Control Block
ReturnCode :Char;
//Retun Code
AdapterStatus :TAdapterStatus;
BEGIN
//Clear NCB Structure
FillChar( NCB, SizeOf(NCB), 0 );
//Programm NBC to fulfill a reset. It doublecheck if the Lana is present.
//Can be removed, when used with GetAdapters.
NCB.ncb_command := Char(NCBRESET);
NCB.ncb_lana_num := Char(AdapterID);
//Process NCB to NetBios
ReturnCode := NetBios(@NCB);
//Check if query was successfull, if returnCode = #0
IF ReturnCode <> #0
THEN
BEGIN
// Return the negative returncode
// Error check would be "if ReturnCode[0]='-' Then..."
Result:=Char(Ord(ReturnCode)*-1);
Exit;
END;
//Clear NCB Structure
FillChar( NCB, SizeOf(NCB), 0 );
//Programm NBC to ask for the MAC associated with the LanaID
NCB.ncb_command := Char(NCBASTAT);
NCB.ncb_lana_num := Char(AdapterID);
NCB.ncb_buffer := @AdapterStatus;
NCB.ncb_length := SizeOf(AdapterStatus);
StrCopy(NCB.ncb_callname, '
* ' );
//Process NCB to NetBios
ReturnCode := Netbios( @NCB );
//Check if query was successfull, if returnCode = #0
IF ReturnCode <> #0
THEN
BEGIN
// Return the negative returncode
Result:=Char(Ord(ReturnCode)*-1);
Exit;
END;
//Return formated MAC
result:=Format('
%2.2x-%2.2x-%2.2x-%2.2x-%2.2x-%2.2x',
[ORD(AdapterStatus.Adapter_address[0]),
ORD(AdapterStatus.Adapter_address[1]),
ORD(AdapterStatus.Adapter_address[2]),
ORD(AdapterStatus.Adapter_address[3]),
ORD(AdapterStatus.Adapter_address[4]),
ORD(AdapterStatus.Adapter_address[5])])
end;
//Function GetAdapter
//=================
//
// This function will return the the total nummber of all lana's istalled
// and a unique the id of each lana.
// E.g. on a system containing lana's 0, 2 and 3, a structure with
// length =3, lana[0]=0, lana[1]=2 and lana[2]=3 will be returned.
FUNCTION GetAdapters: TLanaEnum;
VAR
NCB :TNCB;
//Network Control Block
LanaEnum :TLanaEnum;
//Enumeration of Lan Adapters
ReturnCode :Char;
//Retun Code
BEGIN
//Clear NCB Structure
FillChar(NCB, SizeOf(NCB), 0);
//Clear LanaEnum Stucture
FillChar(LanaEnum, SizeOf(TLanaEnum), 0);
//Programm NBC to ask for the number of Lana's
NCB.ncb_Command := CHAR(NCBENUM);
NCB.ncb_buffer := @LanaEnum;
NCB.ncb_length := Sizeof(LanaEnum);
//Ask NetBios
ReturnCode := NetBios(@NCB);
//Check if query was successfull, if returnCode = #0
IF ReturnCode <> #0
THEN
BEGIN
LanaEnum.Length := CHAR(0);
LanaEnum.Lana[0] := ReturnCode;
END;
// Return valid LanaEnum Structure
Result := LanaEnum;
END;
PROCEDURE TForm1.Button1Click(Sender: TObject);
VAR
L_Enum :TLanaEnum;
i :INTEGER;
BEGIN
L_Enum := GetAdapters;
{ enumerate lanas for WIN NT }
IF L_Enum.Length = '
0'
THEN
BEGIN
Exit;
END;
FOR i:= 0
TO (BYTE(L_Enum.Length) - 1)
DO
BEGIN
ListBox1.Items.Add(getMACaddress(BYTE(L_Enum.Lana[i])));
END;
END;