tags:

views:

170

answers:

4

Hi,

In Code i want to validate a domain name.

For example : " DomainName.com".

How can i do that in C#.

I worked on MSDN Solution. (Second Solution).

But "PingCompletedCallback" is not getting executed.

Thanx

+1  A: 

You could use the Ping class - here's all the info you need on MSDN

Chris W
I tried it But "PingCompletedCallback" is not getting executed.
Jene
+1  A: 

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

  • A domain name can be registered but not connected to a server. Ping requests will fail even though the domain is registered.

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

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

For the first two, I would recommend using a whois service. See for example these C# related questions:

Pekka
A: 

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.");
}

It's untested, but that's the general idea.

bluewall21
I am getting :An unhandled exception of type 'System.Net.NetworkInformation.PingException' occurred in System.dllAdditional information: An exception occurred during a Ping request.
Jene