Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to get the MAC address?

Posted on 2001-06-13
4
Medium Priority
?
320 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
  • 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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

824 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