Detecting local IP address under FireMonkey3

3.7k views Asked by At

Need to detect local IP address under FireMonkey3. In VCL version, I have been using unit WinSock with methods for it

WSAStartup(...)
gethostname(...)

One limitation: don't need to use any third-party library. I am porting ASTA components to FireMonkey3 platform, and don't want to do dependencies among components.

1

There are 1 answers

5
RRUZ On

If you need a cross-platform solution try using Indy and the TIdStack.AddLocalAddressesToList method included in the IdStack unit

Try this sample

var
  AAddresses: TStrings;
begin
  AAddresses := TStringList.Create;
  try
    TIdStack.IncUsage;
    try
      GStack.AddLocalAddressesToList(AAddresses);
    finally
      TIdStack.DecUsage;
    end;
    if AAddresses.Count > 0 then
      //do something
  finally
    AAddresses.Free;
  end;
end;