I want to know how I can check if the domain is a live in c#?
I made this
IPAddress[] addresslist = Dns.GetHostAddresses("domain");
it returns the IP(s), which is good, but I want to check if it is live (like ping)?
I just need to know if the PC is in the same network as the server, so I have a function to check but the functions based on the code above, and it return IPs but I noticed it is based on the cached DNS!
I want to add another check function to see if the server is online!
cheers
The System.Net.NetworkInformation.OperationalStatus Property allow you to detect if your network interface is connected (up).
The NetworkInterface.GetIPProperties Method will give you the IP informations.
You can use this to check if the computer is on lan, then do what you need -like a ping- if connected.
You can use the Ping.Send(IPAddress)
method.
Edit: Or one of the overloads that takes the hostname directly.
Ping.Send(string)
Example from 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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With