Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fast way to check existence of host

Tags:

c#

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...

like image 713
Markus Avatar asked Jan 20 '26 23:01

Markus


1 Answers

IT's not entirely clear what you mean. You could perform DNS resolution with Dns.GetHostEntry(string) which will resolve a name (such as "myurl.com") to a host entry (potentially many addresses)- but that won't tell you if anything is actually using those IP addresses.

What are you trying to accomplish? Usually if you want to find out whether a particular host exists, it's because you want to talk to it using a specific protocol (e.g. HTTP). In that case it's better to make a request with that protocol - otherwise even if the host exists, there's nothing to say it's useful to you.

like image 135
Jon Skeet Avatar answered Jan 22 '26 13:01

Jon Skeet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!