Link to home
Start Free TrialLog in
Avatar of GroundFloor
GroundFloor

asked on

Network cards

Anyone know how to get a list of installed network cards (needs to be able to get all names of nics installed not just one) and their mac addresses?

Avatar of tomerlei
tomerlei

in the registry you can find a list of all network cards: (using the TRegistry component)
HKLM\Software\Microsoft\Windows NT\CurrentVersion\NetworkCards
about the mac address i still need to check.
Avatar of GroundFloor

ASKER

Thanks tomerlei - i know the cards are listed in the registry - just wondered how it could be done to get them all in a stringlist 9or memo) along with each mac address of the card
ASKER CERTIFIED SOLUTION
Avatar of _Katka_
_Katka_
Flag of Czechia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here is code with more info involved:

program GetAdapters;

{$APPTYPE CONSOLE}

uses
  SysUtils,Types,Windows;

const
  MAX_ADAPTER_NAME_LENGTH        = 256;
  MAX_ADAPTER_DESCRIPTION_LENGTH = 128;
  MAX_ADAPTER_ADDRESS_LENGTH     = 8;

  TnTYPE:array[0..28] of AnsiString=('','','','','','','Ethernet','','','Token ring','','','','','','FDDI','','','','','','','','PPP','Loopback','','','','Slip');

type
  PrIP_ADDRESS=^TrIP_ADDRESS;
  TrIP_ADDRESS=record
    Next:PrIP_ADDRESS;
    IpAddress:array[0..15] of Char;
    IpMask:array[0..15] of Char;
    Context:DWORD;
  end;

  PrADAPTER=^TrADAPTER;
  TrADAPTER=record
    FNext:PrADAPTER;
    FComboIndex:DWORD;
    FAdapterName:array[0..MAX_ADAPTER_NAME_LENGTH+3] of Char;
    FDescription:array[0..MAX_ADAPTER_DESCRIPTION_LENGTH+3] of Char;
    FAddrLen:UINT;
    FAddress:array[0..MAX_ADAPTER_ADDRESS_LENGTH-1] of Byte;
    FIndex:DWORD;
    FType:UINT;
    FDHCPEnabled:UINT;
    FCurrentIpAddress:PrIP_ADDRESS;
    FIpAddressList:TrIP_ADDRESS;
    FGatewayList:TrIP_ADDRESS;
    FDHCPServer:TrIP_ADDRESS;
    FHaveWins:BOOL;
    FPrimaryWinsServer:TrIP_ADDRESS;
    FSecondaryWinsServer:TrIP_ADDRESS;
    FLeaseObtained:Longint;
    FLeaseExpires:Longint;
  end;

function GetAdaptersInfo(pAdapterInfo:PrADAPTER;pOutputBuffer:PULONG):DWORD;stdcall;external 'IPHlpAPI.dll' name 'GetAdaptersInfo';

var
  A,Size:DWORD;
  Info:PrADAPTER;
begin
  GetAdaptersInfo(Info,@Size);
  GetMem(Info,Size);
  GetAdaptersInfo(Info,@Size);
// just printout - not needed
  repeat
    WriteLn('Index: ',IntToStr(Info^.FComboIndex));
    WriteLn('Type : ',TnTYPE[Info^.FType]);
    WriteLn('Name : ',AnsiString(Info^.FDescription));
    WriteLn('IP   : ',PChar(@Info^.FIpAddressList.IpAddress));
    WriteLn('Mask : ',PChar(@Info^.FIpAddressList.IpMask));
    WriteLn('G-way: ',PChar(@Info^.FGatewayList.IpAddress));
    WriteLn('DHCP : ',PChar(@Info^.FDHCPServer.IpAddress));
    Write('MAC  : ');
    for A:=0 to Info^.FAddrLen-1 do
    begin
      Write(IntToHex(Info^.FAddress[A],2));
      if A<Info^.FAddrLen-1 then Write('-') else WriteLn(#13#10);
    end;
    Info:=Info^.FNext;
  until not Assigned(Info);
  ReadLn;
end.

regards,
Kate
Katka - thanks, i'll give you code a try out and get back to you.
That worked just as i wanted Katka - thanks a lot
You're welcome :)