Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2007 Nov : Mac address problem

www.cryer.info
Managed Newsgroup Archive

Mac address problem

Subject:Mac address problem
Posted by:"ali karhan" (no..@none.com)
Date:23 Nov 2007 08:18:08

I found below delphi code for get mac address.I test this address with my alot of users.I have seen that Some users have same mac address? is it posible? Or is this code wrong?
How can I get unique mac address?

function GetAdapterInfo(Lana: Char): String;
var
  Adapter: TAdapterStatus;
  NCB: TNCB;
begin
try
  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);
except
  result := '';
end;
end;

function GetMACAddress: string;
var
  AdapterList: TLanaEnum;
  NCB: TNCB;
begin
try
  FillChar(NCB, SizeOf(NCB), 0);
  NCB.ncb_command := Char(NCBENUM);
  NCB.ncb_buffer := @AdapterList;
  NCB.ncb_length := SizeOf(AdapterList);
  Netbios(@NCB);
  result := '';
  if Byte(AdapterList.length) > 0 then
    Result := result + GetAdapterInfo(AdapterList.lana[0])
  else
    Result := ''; //'mac not found';
except
  result := '';
end;
end;

Replies:

www.cryer.info
Managed Newsgroup Archive