Easy way for resolve dns with Indy lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- clauslack · 2012-09-18 13:21 Y try a simple function for convert dns name to ip address. Y try with IdDNSResolver1, but not work Code: [Select]procedure TForm1.Button1Click(Sender: TObject); var x:integer; begin     with IdDNSResolver1 do begin         try             Host := '8.8.8.8';             QueryType := [qtA];             Resolve('www.facebook.com',nil,0);             if QueryResult.Count > 0 then  begin                   Memo1.Lines.Add(QueryResult.Items[0].name);                 end                 else begin                 Memo1.Lines.Add('no work');             end;         finally             Free;         end;     end; end;                  Any idea Thanks ---------------------------------------------------------------------- BeniBela · 2012-09-18 20:55 Why do you want to use Indy for that? Just fpc alone works like that:  Code: [Select]uses netdb; var   temp: THostEntry; begin   ResolveHostByName('google.com', temp);   writeln(temp.Addr.s_bytes[1],'.',temp.Addr.s_bytes[2],'.',temp.Addr. s_bytes[3],'.',temp.Addr.s_bytes[4]); end. ---------------------------------------------------------------------- clauslack · 2012-09-18 21:23 Thanks BeniBela this works fine. ---------------------------------------------------------------------- BeniBela · 2012-09-19 09:23 Some things you might want to be aware of: - need another function for ip6 looks up - on unix, it uses the nameservers from the resolv.conf, it has read at program start => when the file  later changes it is not automatically updated => it may fail if the program is started (e.g. autostart) before an internet connection exists - there is an option to reload a changed resolv.conf, but then it is probably not thread safe anymore ---------------------------------------------------------------------- piola · 2023-01-10 15:49 Quote from: BeniBela on September 18, 2012, 10:55:48 pmWhy do you want to use Indy for that? Just fpc alone works like that:  Code: [Select]uses netdb; var   temp: THostEntry; begin   ResolveHostByName('google.com', temp);   writeln(temp.Addr.s_bytes[1],'.',temp.Addr.s_bytes[2],'.',temp.Addr. s_bytes[3],'.',temp.Addr.s_bytes[4]); end. I'm sorry for replying to this 10-year-old topic, but it's exactly my problem. I just want to do a simple DNS lookup and have been googling quite a lot now. I found dozens of suggestions to use fcl-net and I'd really like to do so. The example BeniBela has posted is all I want to do. Bo no-one has ever mentioned that fcl-net is obviously restricted to *nix. It doesn't compile on Windows because of the use of BaseUnix in netdb.pas. I'd really appreciate a similar example of how to do not more than an hostname-to-IP-address lookup on Windows 🙈 ---------------------------------------------------------------------- MarkMLl · 2023-01-10 16:13 You might be better posting directly into the Windows-specific part of the forum. Speaking as somebody who by and large doesn't use Indy etc., I can say that the fcl-net stuff does still work, and one possibility would be looking to see what makes it unix-specific: WinSock is actually fairly close to the de-facto standard Berkeley Sockets stuff... in fact my notes suggest that the Resolve unit might work with it. MarkMLl ---------------------------------------------------------------------- loaded · 2023-01-10 17:01 This is how I use it in my applications. 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 resolve,StrUtils; function GetHostByName(HostName:String):String;var  host:THostResolver;begin  host := THostResolver.Create(nil);  if host.NameLookup(HostName) then     result := host.AddressAsString   else     result := '';  host.Free;end; procedure TForm1.Button1Click(Sender: TObject);var  host: string;  tip: TStringA rray;begin Host:='https://google.com/'; Host:=ReplaceStr(ReplaceStr(Re placeStr(ReplaceStr(ReplaceStr(Host,'https',''),'http',''),'/',''),'\' ,''),':',''); tip:=GetHostByName(Host).Split('.'); showmessage(tip[0]+ '.'+tip[1]+'.'+tip[2]+'.'+tip[3]);end;    Also, I think you can do it directly with the ping command. But some more code may be required. ---------------------------------------------------------------------- piola · 2023-01-10 17:11 This is working! Thank you!