THostResolver how-to? lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- dg4fac · 2018-02-04 15:42 I tried for several hours now to bring THostResolver to translate an IP to a computer name. I have four edit fields and the following code on edit field 1 (where I type an IP in text form and hit the Enter key): procedure TForm1.Edit1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); var   host:THostResolver; begin If Key=13 Then   begin   host := THostResolver.Create(nil);   if host.NameLookup(Edit1.Text) then     begin     Edit2.Text := ...;     Edit3.Text:=IntToStr(host.AddressCount);     Edit4.Text:=IntToStr(host.AliasCount);     end else     Edit2.Text := '';   host.Free;   end; end; Edit3 and Edit4 work fine, but whatever I try to write to Edit2 is not the desired computer name. host.ResolvedName should be the name, but it simply repeats the IP string that I entered. By going through the resolve.pp I did not find any hint. It remains unclear what the author means by the terms he uses (not very clearly documented). Does someone has some hint? gerd ---------------------------------------------------------------------- TRon · 2018-02-04 17:00 Quote from: dg4fac on February 04, 2018, 04:42:29 pmI tried for several hours now to bring THostResolver to translate an IP to a computer name. Code: [Select]Function GetHostNameByAddress(const AnAddress: String): String; var   Resolver: THostResolver; begin   Result := '';   if AnAddress = '' then exit;   Resolver := THostResolver.Create(nil);   try     if Resolver.AddressLookup(AnAddress) then       Result := Resolver.ResolvedName   finally     FreeAndNil(Resolver);   end; end; Note that the order of the ip address matters on certain platforms: Code: [Select]HostName := GetHostNameByAddress('1.0.0.127'); ---------------------------------------------------------------------- dg4fac · 2018-02-04 17:50 Quote from: TRon on February 04, 2018, 06:00:45 pmQuote from: dg4fac on February 04, 2018, 04:42:29 pmI tried for several hours now to bring THostResolver to translate an IP to a computer name. QuoteCode: [Select]Function GetHostNameByAddress(const AnAddress: String): String; var   Resolver: THostResolver; begin [...]     if Resolver.AddressLookup(AnAddress) then       Result := Resolver.ResolvedName [...] That is one of the things that confuse me in resolve.pp: the use of the terms "Address" and "Name". In my view the "Name" is "www.dg4fac.de", the "Address" is 217.160.231.116. As I am searching for the name I thought that "NameLookup" should be the correct function. As "AddressLookup" with 217.160.231.116 fails I thought that I am correct using "NameLookup". QuoteNote that the order of the ip address matters on certain platforms: Code: [Select]HostName := GetHostNameByAddress('1.0.0.127'); Confusing, like naming me drahreG. The least significant first, sounds nerdy. I tried that with 116.231.160.217, and it is even more confusing: it returns "kundenserver.de", where the site is hosted. And even more confusing: nslookup in Windows with 217. ... delivers "www.dg4fac.de". I am about to give up. gerd ---------------------------------------------------------------------- TRon · 2018-02-05 05:33 Quote from: dg4fac on February 04, 2018, 06:50:42 pmThat is one of the things that confuse me in resolve.pp: the use of the terms "Address" and "Name". In my view the "Name" is "www.dg4fac.de", the "Address" is 217.160.231.116. As I am searching for the name I thought that "NameLookup" should be the correct function. As "AddressLookup" with 217.160.231.116 fails I thought that I am correct using "NameLookup". It is confusing, especially since documentation for these components are pretty much non existent QuoteConfusing, like naming me drahreG. The least significant first, sounds nerdy. Nothing nerdy about that. See also network byte ordering. Usually (and simply put) there is a start-point (host), end-point (remote) and in between (internet). host and remote does not have to know anything about each other and can be totally different systems/platforms. The only agreement is the network byte ordering and some internet related rfc's. QuoteI tried that with 116.231.160.217, and it is even more confusing: it returns "kundenserver.de", where the site is hosted. And even more confusing: nslookup in Windows with 217. ... delivers "www.dg4fac.de". kundenserver.de looks correct to me ? As can also be verified with online tools like ipchecker