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
Solved

MAC address

Posted on 2002-05-06
5
375 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
  • 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

Suggested Solutions

Title # Comments Views Activity
Using idhttp to login to instagram 2 106
Strange behavior when a form is closed 6 60
Multiple image collision 13 80
Multi-layered image in FireMonkey 9 48
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

789 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