Search code examples
c#network-programminghostname

c# check domain is live


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


Solution

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