C # check domain live

I want to know how can I check if a domain is alive in C #?

I did it

IPAddress[] addresslist = Dns.GetHostAddresses("domain");

it returns IP (s), which is good, but I want to check if it is alive (like ping)?

I just need to know if the computer is on the same network as the server, so I have a check function, but the functions are based on the code above and they return IP addresses, but I noticed that it is based on cached DNS

I want to add another check function to see if the server is on the network!

amuses

+3
source share
3 answers
+6

Ping.Send(IPAddress).

: , . Ping.Send(string)

MSDN:

Ping pingSender = new Ping ();
PingReply reply = pingSender.Send ("www.contoso.com");
if (reply.Status == IPStatus.Success)
{
    Console.WriteLine ("Address: {0}", reply.Address.ToString ());
    Console.WriteLine ("RoundTrip time: {0}", reply.RoundtripTime);
    Console.WriteLine ("Time to live: {0}", reply.Options.Ttl);
    Console.WriteLine ("Don't fragment: {0}", reply.Options.DontFragment);
    Console.WriteLine ("Buffer size: {0}", reply.Buffer.Length);
}
else
{
    Console.WriteLine (reply.Status);
}
+4

- , , - 100% , .

The only normal task is to try to complete the task necessary for execution and to eliminate errors, timeouts, etc. in a safe way. This may allow the user to find out about the failure or try again (possibly with an increase in the delay between each attempt) or simply register the error somewhere.

0
source

Source: https://habr.com/ru/post/1772989/


All Articles