• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 447
  • Last Modified:

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?

0
GroundFloor
Asked:
GroundFloor
  • 3
  • 3
1 Solution
 
tomerleiCommented:
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.
0
 
GroundFloorAuthor Commented:
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
0
 
_Katka_Commented:
Hi, test this code (it'll determine network card Name,IP,MAC and much more not visualised):

program GetAdapters;

{$APPTYPE CONSOLE}

uses
  SysUtils,Types,Windows;

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

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('Name: ',AnsiString(Info^.FDescription));
    WriteLn('IP  : ',PChar(@Info^.FIpAddressList.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('-');
    end;
    WriteLn(#13#10);
    Info:=Info^.FNext;
  until not Assigned(Info);
  ReadLn;
end.

regards,
Kate
0
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!

 
_Katka_Commented:
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
0
 
GroundFloorAuthor Commented:
Katka - thanks, i'll give you code a try out and get back to you.
0
 
GroundFloorAuthor Commented:
That worked just as i wanted Katka - thanks a lot
0
 
_Katka_Commented:
You're welcome :)
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!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now