How to ping a domain name?

In the code, I want to validate the domain name.

For example: "DomainName.com".

How can I do this in C #.

I've worked on MSDN Solution. (Second solution).

But "PingCompletedCallback" is not being executed.

Thanx

+2


a source to share


4 answers


There is a class for this:

MSDN article on System.Net.NetworkInformation.Ping



GeekPedia article on asynchronous ping

+2


a source


I don't think pinging a domain name will tell you anything relevant in a reliable way.

  • The domain name can be registered but not connected to the server. Ping requests will fail even if the domain is registered.

  • The server can be fully operational, but must be configured not to respond to ping requests. Ping requests fail even if the domain is registered and running on the server.

What do you want to do - find out if the domain is registered, is it a valid domain name, or a working website / mail server ...?



For the first two, I would recommend using a service whois

. See for example C # related questions:

+2


a source


Using the System.Net.NetworkInformation.Ping class,

using System.Net.NetworkInformation;

Ping sender = new Ping();
PingReply reply = sender.Send ("www.example.com");

if (reply.Status == IPStatus.Success)
{
  Console.WriteLine("Ping successful.");
}

      

This is untested, but that's the general idea.

+2


a source


You can use the Ping class - here is all the information you need on MSDN

+1


a source







All Articles