Jump to content
ChrisChuah

Get Mac Address using Indy?

Recommended Posts

Hi

Is there a function in Indy whereby i could get the Mac address of the interface card?

Or is there any function in Delphi whereby i could obtain the MAC address of the NIC card for FMX app?

 

regards

chris

Edited by ChrisChuah

Share this post


Link to post

I don't know with Indy, but in Delphi there are the WinApi.IPHlpApi e WinAPi.IPTypes that are acquired from Project JEDI.

 

You must enumerate the Interface cards and looks for properties:

 

Uses WinAPi.IpHlpApi, WinApi.IpTypes;

var
  NumInterfaces: Cardinal;
  AdapterInfo: array of TIpAdapterInfo;
  OutBufLen: ULONG;
begin
  GetNumberOfInterfaces(NumInterfaces);
  SetLength(AdapterInfo, NumInterfaces);
  OutBufLen := NumInterfaces * SizeOf(TIpAdapterInfo);
  GetAdaptersInfo(@AdapterInfo[0], OutBufLen);

  for var i := 0 to NumInterfaces - 1 do
    begin
      (* These are the 6 bytes MAC Addresses of Interfaces
      AdapterInfo[i].Address[0], AdapterInfo[i].Address[1]
      AdapterInfo[i].Address[2], AdapterInfo[i].Address[3]
      AdapterInfo[i].Address[4], AdapterInfo[i].Address[5]
	  *)
  end;
end;

EDIT: This works only in Windows platforms.

 

Edited by DelphiUdIT

Share this post


Link to post
12 hours ago, ChrisChuah said:

Is there a function in Indy whereby i could get the Mac address of the interface card?

No.  Indy does not operate at the ethernet layer, so it has no need for MAC addresses.

12 hours ago, ChrisChuah said:

Or is there any function in Delphi whereby i could obtain the MAC address of the NIC card for FMX app?

You will have to use platform-specific APIs, like GetAdaptersInfo()/GetAdaptersAddresses() on Windows, getifaddrs() on Posix, etc to get that kind of information directly from the OS.

Edited by Remy Lebeau

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×