Delphi Ultimate Component Suite To Easily Detect The Network Adapters In Your Windows Apps

FireWind

Свой
Регистрация
2 Дек 2005
Сообщения
1,957
Реакции
1,199
Credits
4,009
Ultimate Component Suite To Easily Detect The Network Adapters In Your Windows Apps
February 13, 2021 By Anbarasan

Do you need to access Network Adapter information from you Delphi applications? Detecting the available network Adapters information is no more a challenging task. Для просмотра ссылки Войди или Зарегистрируйся System Information Management Suite’s component helps to detect easily the network adapters and we will learn how to use TMiTeC_Network and TMiTeC_TCPIP component in this blog post.

Platforms: Windows.

Installation Steps:

You can easily install this Component Suite from GetIt Package Manager. The steps are as follows.
  1. Navigate In RAD Studio IDE->Tools->GetIt Package Manager->select Components in Categories->Components->Trail -MiTec system Information Component Suite 14.3 and click Install Button.
  2. Read the license and Click Agree All. An Information dialog saying ‘Requires a restart of RAD studio at the end of the process. Do you want to proceed? click yes and continue.
  3. It will download the plugin and installs it. Once installed Click Restart now.
How to run the Demo app:
  • Navigate to the System Information Management Suite trails setup, Demos folder which is installed during Get It installation e.g) C:UsersDocumentsEmbarcaderoStudio21.0CatalogRepositoryMiTeC-14.3DemosDelphi17
  • Open the IntfList project in RAD studio 10.4.1 compile and Run the application.
  • This Demo App shows how to detect the Network Adapters and its properties such as Interface, IPAddress, MACAddress etc.
1613214247134.png
Components used in MSIC IntfList Demo App:
  • TMiTeC_Network: Retrieves network environment information. Using this component, we can access Network resources and WinSock properties.
  • TMiTeC_TCPIP: Enumerates network adapters, their properties and network configuration.
  • TListView To list down the list of detected TCPIP Network Adapters.
Implementation Details:
  • An instance FNetwork of TMiTeC_Network is created. Loop through the TCPIP.AdapterCount property to detect the available network adapters. For each TCPIP.Adpater record list down the properties such as Interface Name, IPAddress, IPAddressMask, Address, Typ, OperStatus, AdminStatus, Speed in the list view.
Код:
procedure TwndMain.RefreshData;
var
  i: Integer;
begin
  FNetwork.RefreshData;
  List.Items.BeginUpdate;
  try
    List.Items.Clear;
    for i:=0 to FNetwork.TCPIP.AdapterCount-1 do
      with List.Items.Add do begin
        Caption:=FNetwork.TCPIP.Adapter[i].Name;
        SubItems.Add(FNetwork.TCPIP.Adapter[i].IPAddress.CommaText);
        SubItems.Add(FNetwork.TCPIP.Adapter[i].IPAddressMask.CommaText);
        SubItems.Add(FNetwork.TCPIP.Adapter[i].Address);
        SubItems.Add(AdapterTypes[FNetwork.TCPIP.Adapter[i].Typ]);
        SubItems.Add(GetIntfStatStr(FNetwork.TCPIP.Adapter[i].OperStatus));
        SubItems.Add(GetIntfAdminStr(FNetwork.TCPIP.Adapter[i].AdminStatus));
        SubItems.Add(IntToStr(FNetwork.TCPIP.Adapter[i].MaxSpeed div 1000000));
        SubItems.Add(IntToStr(FNetwork.TCPIP.Adapter[i].MTU));
        if FNetwork.TCPIP.BestInterfaceIdx=FNetwork.TCPIP.Adapter[i].IntfIdx then
          ImageIndex:=0
        else
          ImageIndex:=-1;
      end;
  finally
    List.Items.EndUpdate;
  end;
end;
1613214309116.png
MiTeC_Network Demo
  • On Double clicking a selected row, the interface properties were shown in the child form.
Код:
procedure ShowIntfProps(Adapter: TAdapter);
begin
  dlgIntf:=TdlgIntf.Create(Application.Mainform);
  with dlgIntf do
    try
      Caption:=Adapter.Name;
      with List.Items.Add do begin
        Caption:='Description';
        SubItems.Add(Adapter.Name);
      end;
      with List.Items.Add do begin
        Caption:='Alias';
        SubItems.Add(Adapter.Alias);
      end;
      with List.Items.Add do begin
        Caption:='MAC Address';
        SubItems.Add(Adapter.Address);
      end;
      with List.Items.Add do begin
        Caption:='MTU';
        SubItems.Add(IntToStr(Adapter.MTU));
      end;
      with List.Items.Add do begin
        Caption:='Link speed';
        SubItems.Add(Format('%d Mbps',[Adapter.MaxSpeed div 1000000]));
      end;
      with List.Items.Add do begin
        Caption:='Type';
        SubItems.Add(AdapterTypes[Adapter.Typ]);
      end;
      with List.Items.Add do begin
        Caption:='DNS connection suffix';
        SubItems.Add(Adapter.DNSSuffix);
      end;
      with List.Items.Add do begin
        Caption:='DHCP Enabled';
        SubItems.Add(BoolToStr(Adapter.EnableDHCP,True));
      end;
      with List.Items.Add do begin
        Caption:='IPv4';
        SubItems.Add(Adapter.IPAddress.CommaText);
      end;
      with List.Items.Add do begin
        Caption:='IPv4 Mask';
        SubItems.Add(Adapter.IPAddressMask.CommaText);
      end;
      with List.Items.Add do begin
        Caption:='IPv4 DHCP Servers';
        SubItems.Add(Adapter.DHCP_IPAddress.CommaText);
      end;
      with List.Items.Add do begin
        Caption:='IPv4 Default Gateway';
        SubItems.Add(Adapter.Gateway_IPAddress.CommaText);
      end;
      with List.Items.Add do begin
        Caption:='IPv4 DNS Servers';
        SubItems.Add(Adapter.DNSServers.CommaText);
      end;
      with List.Items.Add do begin
        Caption:='IPv4 WINS Servers';
        SubItems.Add(Adapter.PrimaryWINS_IPAddress.CommaText);
      end;
 
      with List.Items.Add do begin
        Caption:='IPv6';
        SubItems.Add(Adapter.IPv6Address.CommaText);
      end;
      with List.Items.Add do begin
        Caption:='IPv6 DHCP Servers';
        SubItems.Add(Adapter.DHCP_IPv6.CommaText);
      end;
      with List.Items.Add do begin
        Caption:='IPv6 Default Gateway';
        SubItems.Add(Adapter.Gateway_IPv6.CommaText);
      end;
      with List.Items.Add do begin
        Caption:='IPv6 DNS Servers';
        SubItems.Add(Adapter.DNSServers_IPv6.CommaText);
      end;
      with List.Items.Add do begin
        Caption:='IPv6 WINS Servers';
        SubItems.Add(Adapter.PrimaryWINS_IPv6.CommaText);
      end;
      ShowModal;
    finally
      Free;
    end;
end;
1613214338427.png
Network Ethernet Adapter Property

It’s that simple to enumerate list of network adapters and its properties available in your machine from your Delphi application. Use this MiTeC component suite and get the job done quickly.

Head over and check out the full MiTec System Information Management Suite for Access System Information for Windows in Delphi Applications