0
votes

I can get all local IP addresses using this code with indy:

uses IdStack;

var
  IPs: TStringList;
begin
  IPs := TStringList.Create;
  try
    GStack.AddLocalAddressesToList(IPs);
    listbox_localIPs.Items.Assign(IPs);  //My listbox
  finally
    IPs.Free;
  end;
end;

How can I get Adapter Name for each IP I find with Indy?

2

2 Answers

3
votes

Indy doesn't provide such info. You must use WinApi (GetAdaptersInfo, GetAdaptersAddresses) or WMI (Win32_NetworkAdapter).

2
votes

Indy is primarily just a wrapper around standard socket APIs that do not expose adapter information. AddLocalAddressesToList() uses platform-specific APIs to get the local IPs, and some of those APIs may report adapter names (or expose ways to look up those names through other APIs), but AddLocalAddressesToList() simply fills a TStrings with IP address strings, so it has no way of reporting adapter names even if it wanted to.

With that said, AddLocalAddressesToList() has recently been deprecated in favor of a new GetLocalAddressList() method, which returns a collection of TIdStackLocalAddress-derived objects containing additional information (IP version, subnet mask). So it is feasible that a future release might add adapter names, but that would still be implemented on a platform-specific basis and thus may not be available on all platforms. Indy itself does not need adapter names, so you are best off simply using platform-specific APIs directly to get whatever adapter information you need.