Solved

How to get the MAC address?

Posted on 2001-06-13
4
306 Views
Last Modified: 2010-04-04
I need to get the MAC address in Delphi. There's an example which uses CoCreateGuid, but this is not the solution because as of Windows 2000 Microsoft doesn't use the MAC address any more (or encrypts it in the GUID, don't know) because of privacy.

Please post a working solution, for that I give 250 points. Thanks.

By the way (maybe this is another question), it really would be nice if the same program works on Kylix, too.
0
Comment
Question by:dnoelpp
[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
  • 2
  • 2
4 Comments
 
LVL 3

Author Comment

by:dnoelpp
ID: 6185203
Please don't post answers, I found the answer just now, 5 minutes ago and will delete this question. thanks!
0
 
LVL 8

Accepted Solution

by:
Cesario earned 250 total points
ID: 6185205
From Microsoft:
http://support.microsoft.com/support/kb/articles/Q118/6/23.asp


The Delphi Translation

uses
  NB30;

function GetAdapterInfo(Lana: Char): String;
var
  Adapter: TAdapterStatus;
  NCB: TNCB;
begin
  FillChar(NCB, SizeOf(NCB), 0);
  NCB.ncb_command := Char(NCBRESET);
  NCB.ncb_lana_num := Lana;
  if Netbios(@NCB) <> Char(NRC_GOODRET) then
  begin
    Result := 'mac not found';
    Exit;
  end;

  FillChar(NCB, SizeOf(NCB), 0);
  NCB.ncb_command := Char(NCBASTAT);
  NCB.ncb_lana_num := Lana;
  NCB.ncb_callname := '*';

  FillChar(Adapter, SizeOf(Adapter), 0);
  NCB.ncb_buffer := @Adapter;
  NCB.ncb_length := SizeOf(Adapter);
  if Netbios(@NCB) <> Char(NRC_GOODRET) then
  begin
    Result := 'mac not found';
    Exit;
  end;
  Result :=
    IntToHex(Byte(Adapter.adapter_address[0]), 2) + '-' +
    IntToHex(Byte(Adapter.adapter_address[1]), 2) + '-' +
    IntToHex(Byte(Adapter.adapter_address[2]), 2) + '-' +
    IntToHex(Byte(Adapter.adapter_address[3]), 2) + '-' +
    IntToHex(Byte(Adapter.adapter_address[4]), 2) + '-' +
    IntToHex(Byte(Adapter.adapter_address[5]), 2);
end;

function GetMACAddress: string;
var
  AdapterList: TLanaEnum;
  NCB: TNCB;
begin
  FillChar(NCB, SizeOf(NCB), 0);
  NCB.ncb_command := Char(NCBENUM);
  NCB.ncb_buffer := @AdapterList;
  NCB.ncb_length := SizeOf(AdapterList);
  Netbios(@NCB);
  if Byte(AdapterList.length) > 0 then
    Result := GetAdapterInfo(AdapterList.lana[0])
  else
    Result := 'mac not found';
end;

Best Regards

Cesario
0
 
LVL 3

Author Comment

by:dnoelpp
ID: 6185292
Hey Cesario

The other solution I found was not so good as yours. So I decided to cancel the deletion and give you all 250 points.

I realized that you did really good work here!!! Please tell me a little more about how you translated the vb code to Delphi! I didn't know about the NB30 unit, but this was exactly the missing bit I needed. How did you know about it?

Thanks very much and please forgive me for raising a hell of confusion with deleting the question etc.
0
 
LVL 8

Expert Comment

by:Cesario
ID: 6185318
Hello dnoelpp,

the NB3 Unit is in your delphi Folder:

..\Delph4\Source\RTL\Win...

I get the translation from Knowledge Base in ower Company.
Some one put it in the Database. I think i get it from Delphi3000.com

Best Regards

Cesario
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

734 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