Solved

Read Hardware MAC-Address

Posted on 2004-04-23
11
177 Views
Last Modified: 2010-04-05
Hi All!

I was just wondering if there was a way to read the original MAC-address that was burned into the Network Card. I am (almost too) aware that there is ways to change the MAC-Address of a NIC in the Windows registry, so I am looking for a way to query the physical (original) manufacturer-specified MAC.

Thanks in advance,

Enune
0
Comment
Question by:enune
11 Comments
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10897200
function CoCreateGuid(var guid: TGUID): HResult; stdcall; far external 'ole32.dll';

function Get_MACAddress: string;
var
  g: TGUID;
  i: Byte;
begin
  Result := '';
  CoCreateGUID(g);
  for i := 2 to 7 do
    Result := Result + IntToHex(g.D4[i], 2);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Label1.Caption := Get_MACAddress;
end;
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10897235
0
 
LVL 11

Expert Comment

by:calinutz
ID: 10897483
uses NB30;

function GetMACAdress: string;
var
  NCB: PNCB;
  Adapter: PAdapterStatus;

  URetCode: PChar;
  RetCode: char;
  I: integer;
  Lenum: PlanaEnum;
  _SystemID: string;
  TMPSTR: string;
begin
  Result    := '';
  _SystemID := '';
  Getmem(NCB, SizeOf(TNCB));
  Fillchar(NCB^, SizeOf(TNCB), 0);

  Getmem(Lenum, SizeOf(TLanaEnum));
  Fillchar(Lenum^, SizeOf(TLanaEnum), 0);

  Getmem(Adapter, SizeOf(TAdapterStatus));
  Fillchar(Adapter^, SizeOf(TAdapterStatus), 0);

  Lenum.Length    := chr(0);
  NCB.ncb_command := chr(NCBENUM);
  NCB.ncb_buffer  := Pointer(Lenum);
  NCB.ncb_length  := SizeOf(Lenum);
  RetCode         := Netbios(NCB);

  i := 0;
  repeat
    Fillchar(NCB^, SizeOf(TNCB), 0);
    Ncb.ncb_command  := chr(NCBRESET);
    Ncb.ncb_lana_num := lenum.lana[I];
    RetCode          := Netbios(Ncb);

    Fillchar(NCB^, SizeOf(TNCB), 0);
    Ncb.ncb_command  := chr(NCBASTAT);
    Ncb.ncb_lana_num := lenum.lana[I];
    // Must be 16
    Ncb.ncb_callname := '*               ';

    Ncb.ncb_buffer := Pointer(Adapter);

    Ncb.ncb_length := SizeOf(TAdapterStatus);
    RetCode        := Netbios(Ncb);
    //---- calc _systemId from mac-address[2-5] XOR mac-address[1]...
    if (RetCode = chr(0)) or (RetCode = chr(6)) then
    begin
      _SystemId := IntToHex(Ord(Adapter.adapter_address[0]), 2) + '-' +
        IntToHex(Ord(Adapter.adapter_address[1]), 2) + '-' +
        IntToHex(Ord(Adapter.adapter_address[2]), 2) + '-' +
        IntToHex(Ord(Adapter.adapter_address[3]), 2) + '-' +
        IntToHex(Ord(Adapter.adapter_address[4]), 2) + '-' +
        IntToHex(Ord(Adapter.adapter_address[5]), 2);
    end;
    Inc(i);
  until (I >= Ord(Lenum.Length)) or (_SystemID <> '00-00-00-00-00-00');
  FreeMem(NCB);
  FreeMem(Adapter);
  FreeMem(Lenum);
  GetMacAdress := _SystemID;
end;



procedure TForm1.Button1Click(Sender: TObject);
begin
  label1.Caption := GetMACAdress;
end;
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10897768

    calinutz, the same as the link in my post above ...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:enune
ID: 10945113
Sorry guys, but those solutions still return the spoofed MAC if a user has set the correct registry keys... Also, Ivanov_G - Your first solution generates a random MAC address! I hardly think that'd help me =)

Does anyone know of any calls for this? I'd be willing to write a helperDLL in C/C++ if I had to do it that way.
0
 

Author Comment

by:enune
ID: 11200169
C'mon people! I'll up the points to 400 if someone can provide a solution to this problem =)
0
 

Author Comment

by:enune
ID: 11412510
Cleanup time - This question either will not or can not be answered.. Would a mod care to close?

Regards,

Enune
0
 

Author Comment

by:enune
ID: 13189617
A refund would be good, as no correct answer was provided.

Thank you,
Calum
0
 

Accepted Solution

by:
PAQ_Man earned 0 total points
ID: 15015559
PAQed with points refunded (125)

PAQ_Man
Community Support Moderator
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
loading dll from external path 1 211
Delphi component that can load a DLL in design time? 8 53
Working with hours 3 46
TEMBEDDEDWB how can i change its user agent ? 8 48
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

910 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now