(Moderator)
Registriert seit: 23. Sep 2003
Ort: Bockwen
12.235 Beiträge
Delphi 2006 Professional
|
Re: MAC Adresse aller Netzwerk Karten ermitteln
22. Mär 2006, 22:57
ich benutze dafür folgende funktionen:
Delphi-Quellcode:
uses
[...], nb30, [...]
function GetAdapterInfo(Lana: Char): String;
var
Adapter: TAdapterStatus;
NCB: TNCB;
begin
FillChar(NCB, SizeOf(NCB), 0);
NCB.ncb_command := Char(NCBRESET);
NCB.ncb_lana_num := Lana;
if Netbios(@NCB) <> Char(NRC_GOODRET) then
begin
Result := 'mac not found';
Exit;
end;
FillChar(NCB, SizeOf(NCB), 0);
NCB.ncb_command := Char(NCBASTAT);
NCB.ncb_lana_num := Lana;
NCB.ncb_callname := '*';
FillChar(Adapter, SizeOf(Adapter), 0);
NCB.ncb_buffer := @Adapter;
NCB.ncb_length := SizeOf(Adapter);
if Netbios(@NCB) <> Char(NRC_GOODRET) then
begin
Result := 'mac not found';
Exit;
end;
Result :=
IntToHex(Byte(Adapter.adapter_address[0]), 2) + '-' +
IntToHex(Byte(Adapter.adapter_address[1]), 2) + '-' +
IntToHex(Byte(Adapter.adapter_address[2]), 2) + '-' +
IntToHex(Byte(Adapter.adapter_address[3]), 2) + '-' +
IntToHex(Byte(Adapter.adapter_address[4]), 2) + '-' +
IntToHex(Byte(Adapter.adapter_address[5]), 2);
end;
{==============================================================================}
function GetMacAddressCount: Byte;
var AdapterList: ^TLanaEnum;
NCB: TNCB;
begin
new(AdapterList);
FillChar(NCB, SizeOf(NCB), 0);
NCB.ncb_command := Char(NCBENUM);
NCB.ncb_buffer := PChar(AdapterList);
NCB.ncb_length := SizeOf(AdapterList^);
Netbios(@NCB);
Result := Byte(AdapterList.length);
dispose(AdapterList);
end;
function GetMACAddress(ANewworkcardIndex: Byte = 0): string;
var AdapterList: TLanaEnum;
NCB: TNCB;
begin
FillChar(NCB, SizeOf(NCB), 0);
AdapterList.length := char(0);
NCB.ncb_command := Char(NCBENUM);
NCB.ncb_buffer := @AdapterList;
NCB.ncb_length := SizeOf(AdapterList);
Netbios(@NCB);
if Byte(AdapterList.length) > ANewworkcardIndex then
Result := GetAdapterInfo(AdapterList.lana[ANewworkcardIndex])
else
Result := 'mac not found';
end;
Jens Mit Source ist es wie mit Kunst - Hauptsache der Künstler versteht's
|
|
Zitat
|