INDY 10 - TIdIPWatch returns '' (same problem with IDStack) lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- kevin.black · 2019-05-07 02:02 Hi, I'm looking at simple solutions to get the local IP Address and certainly INDY seems simplest.  That would be, of course, if it worked. This is on a parallels MacOS VM running Mojave running on a 2015 MBP. I'm using Lazarus 2.0.0RC3 and the code is in a DYLIB. I need the IP address of the local machine to get it's MACAddress. I'm using TIdWatch, which should simply return the Local IP address (which is also used in Current IP Address function(. I like both solutions, IdStack below, because the code is very simple, but, of course, no matter how simple not of benefit if the code does not work: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Uses  IdBaseComponent,  IdComponent,  IdIPWatch,.........function getLocalIP: string;var   IPW: TIdIPWatch; begin  IpW := TIdIPWatch.Create(nil);  try    if IpW.LocalIP <> '' then      Result := IpW.LocalIP;    showmessage('IP: ' + Result);  finally    IpW.Free;  end;end; So basically the call to the function is returning '' (the local IP address is 192.168.1.25). I tried setting active to True (IpW.Active := True;), but that just kills the application. Any ideas what I'm doing wrong or what I might need to setup???? Likewise I have tried using IdStack and get the same issue, ie. it Returns '': Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Uses  IdStack,......function GetLocalIP : String;begin  TIdStack.IncUsage;  try    Result := GStack.LocalAddress;    showmessage('IP: ' + Result);  finally    TIdStack.DecUsage;  end;end;  Again, this code was from the internet, but I have looked up both IdStack and TIdIPWatch and according to my readings, should return the local IP address as stated on the website. Again, anyone got any ideas what I might be doing wrong? EDIT: I also tried this modified code, but it returns an index out of bounds error, clearly nothing is being returned to the stringiest by the AddLocalAddressesToList function: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function getLocalIP: string;var  IPStrings: TStringList; begin  try    try    Result:='';      IPStrings:=TStringList.Create();       TIdStack.IncUsage;      GStack.AddLocalAddressesToList(IPStrings);    Result := IPStrings[0];      showmessage('IP: ' + Result);    except      On E:Exception do      begin        Result := '';       showmessage('IP Error: ' + E.message);      end;    end;  finally    TIdStack.DecUsage;  end; end;  Kevin ---------------------------------------------------------------------- JimD · 2019-05-11 19:55 Your first example using TIdIPWatch works for me. Using: Windows 10, Lazarus 1.8.4, Indy10.6.2.5494 ---------------------------------------------------------------------- Remy Lebeau · 2019-05-11 20:30 Quote from: jasc2v8 on May 11, 2019, 09:55:25 pmYour first example using TIdIPWatch works for me. Using: Windows 10, Lazarus 1.8.4, Indy10.6.2.5494 That is because retrieving the local IPs is well-tested on Windows.  I made sure of that, as I am a Windows developer myself and have put a lot of effort into the retrieval code on Windows.  But the retrieval code for other platforms is less tested, as I don't develop for other platforms, I rely on support from community Delphi/FPC members for that. ---------------------------------------------------------------------- Remy Lebeau · 2019-05-11 21:10 FYI, there is a related discussion on StackOverflow for this same issue: TIdIPWatch returns blank IP (as does TIdStack) ---------------------------------------------------------------------- kevin.black · 2019-05-17 02:02 @Remy, Yes, many thanks, that was me...... I didn't get a response here so posted to stackOverflow. Apologies if it caused additional, unnecessary work, I should have cross- referenced, my bad. Kevin