In C#:
If I ping a url (eg. “http://myurl.com”) and that url doesn’t exist I get a SocketException (No such host is know). This request is a very fast way to determine if a address exist. Is there any similar way to check if an IP “exists”?
Obviously there is the possibility to ping the IP, but if the host is located in china (and I’m located in Sweden) then the ping time gets very long…
No, there is no foolproof way to check if an IP is used since the use is not registered anywhere.
The reason the hostname check is fast is that you don’t need to actually talk to the host to figure out whether the hostname exists, it’s registered in the DNS system.
The hostname check you’re doing in no way guarantees that the host actually exists, just that an alias from the hostname to an IP number exists, the host may well be down and you won’t know from that lookup.
Also, even if you use ping to try to figure out if an IP is used, you’re not sure since there may be a firewall blocking ping and still letting other IP traffic through (HTTP for example). To best know if a host available to serve your requests, you’re best off polling it using the actual protocol you’re interested in.