Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MAC address

Posted on 2002-05-06
5
Medium Priority
?
383 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 1200 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

705 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