Solved

MAC address

Posted on 2002-05-06
5
376 Views
Last Modified: 2010-04-04
Is there a better way to get MAC address from lan adapter.
This one require microsoft client for network to be installed.

Ex1….  

function CoCreateGuid(P:Pointer):Integer;stdcall;external 'ole32.dll';


function GetNicAddr:AnsiString;
var
  T:AnsiString;
  I:Integer;
  result2:String;
begin
  Result:='';
  Result2:='';
  SetLength(T,16);
  if CoCreateGUID(@T[1])=S_OK then begin
  for I:=11 to 15 do Result2:=Result2+IntToHex(Ord(T[I]),2);
  macout:=Result2+IntToHex(Ord(T[16]),2);
  ShowMessage(macout);
 end;
end;
0
Comment
Question by:Dark_King
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
Cesario earned 300 total points
ID: 6991176
Hi Dark King,

first thanx for the point of your prev. Question ;-)


Try this:

{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 + Unit.............MACADRESS.PAS
 + Description...... Retrive the Hardware-Adress of an ethernet adapther
 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
unit MacAdress;

interface

uses SysUtils,NB30;

type
  TMACAdress  = array[0..5] of byte;
  ENCBError   = class(Exception);

function GetMACAdress(AdapterNum:byte):TMACAdress;
function MACAdressToStr(aMACAdr:TMACAdress):string;
function IsMACAdress(aMACAdr:TMACAdress):boolean;

var
  MacAdressFormat:string;

implementation

ResourceString
  SNCBError='NetBios-Fehler %d';

type TAStat=packed record
              Adapter_Status:TAdapterStatus;
              Name_Buffer:array[0..49] of TNameBuffer;
            end;

function MACAdressToStr(aMACAdr:TMACAdress):string;
begin
  Result:=Format( MacAdressFormat,
                  [aMACAdr[0],
                  aMACAdr[1],
                  aMACAdr[2],
                  aMACAdr[3],
                  aMACAdr[4],
                  aMACAdr[5]]
                );
end;

procedure CheckResult(aReturnCode:char);
  begin
    if Byte(aReturnCode)<>NRC_GOODRET then
      raise ENCBError.Create(Format(SNCBError,[byte(aReturnCode)]));
  end;

function IsMACAdress(aMACAdr:TMACAdress):boolean;
  var i:integer;
  begin
    for i:=0 to 5 do if aMACAdr[i]<>0 then begin Result:=True; exit end;
    Result:=False;
  end;

function GetMACAdress(AdapterNum:byte):TMACAdress;
  var Adapter:TAStat;
      NCB:TNCB;
  begin
    FillChar(NCB,SizeOf(NCB),0);
    NCB.ncb_command:=char(NCBRESET);
    NCB.ncb_lana_num:=char(AdapterNum);
    CheckResult(NetBIOS(@NCB));

    FillChar(NCB,SizeOf(NCB),0);
    NCB.ncb_command:=char(NCBASTAT);
    NCB.ncb_lana_num:=char(AdapterNum);

    StrCopy(NCB.ncb_callname,'*               ');
    NCB.ncb_buffer:=@Adapter;
    NCB.ncb_length:=sizeof(Adapter);
    CheckResult(NetBIOS(@NCB));

    Move(Adapter.Adapter_Status.adapter_address[0],Result[0],SizeOf(Result));
  end;

initialization
  MacAdressFormat:='%2.2x-%2.2x-%2.2x-%2.2x-%2.2x-%2.2x';
end.
0
 
LVL 8

Expert Comment

by:Cesario
ID: 6991198
Exmaple:

procedure TForm1.Button1click(Sender: TObject);
begin
  showMessage ( MACAdressToStr(GetMACAdress(0)));
end;
0
 
LVL 6

Author Comment

by:Dark_King
ID: 6991228
I not 100% shore but I think you need Microsoft client as you call fore netbios funktion..

I have test a Nb30 before and it didn’t work on all computers,, best would be to use same ass
Microsoft use in winipcfg or ipconfig /all…  
0
 
LVL 6

Author Comment

by:Dark_King
ID: 6991288
I while test this one at home to night, cu to morrow..
0
 
LVL 6

Author Comment

by:Dark_King
ID: 6993121
Great  (**lol**)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question