Performing DNS Lookup of IP Addresses? lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- Gizmo · 2013-04-12 22:33 My program searches for certain magic markers relating to IP addresses, and, if found, it then parses a series of 4 individual bytes at a a certain offset from this marker. As it parses each byte one by one, each one can not not exceed 255 but can be any range from 0 to 255. By and large, this results in genuine results and the result is a concatanated IntToStr of all 4 bytes seperated by a dot that I then display as a string in a grid. However, I'd like to weed out the few that coincidentally are not actually IP addresses by doing some kind of lookup. I'm curious to know whether there is any in built functionality in FPC to do a DNS lookup of sorts to say "is the IP address real or not"? If so, how to do that?  I found INEt (http://www.freepascal.org/packages/inet.html) and assume that is what I will need (specifically GetHostByAddr ?)  but wanted to check there was not another (better?) way? Have done some Googling but all the replies seem to relate to using Reg Exp to validate string patterns, which is not what I am seeking. Thanks ---------------------------------------------------------------------- Ocye · 2013-04-15 14:05 Why don't you check with the calling function, e.g. when you fail connecting to the IP address. I don't think that there is any hash sum to make sure the IP is valid. And what should it mean to know that 192.168.235.176 (just to use a strange local address) could be a good address? ---------------------------------------------------------------------- BigChimp · 2013-04-15 14:46 I think you're confusing some things: 1. A DNS lookup by default looks up an IP address from a name. You would be after a reverse DNS lookup: going from name to IP address. AFAIU, not all hosts have these reverse entries; many don't. 2. IP addresses that may not be valid now could have been valid 2 days ago before a dynamic IP assignment changed an ADSL subscriber's IP address. There's no way to check for that. 3. If you want to know if an IP address exists now, you could try pinging it. Of course there's a snag: no response may just mean paranoid administrator or strict firewall Or, as Ocye says, just try connecting to it. 4. You could filter out private ip ranges and there are overviews of which IP blocks are assigned to which countries/corporations etc.  Depending on your purpose, that may help.