Solved

Read Hardware MAC-Address

Posted on 2004-04-23
11
176 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 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

15 Experts available now in Live!

Get 1:1 Help Now