How to "ping" a domain name?
In Code i want to validate a domain name.
For example : " Doma开发者_开发技巧inName.com".
How can i do that in C#.
I worked on MSDN Solution. (Second Solution).
But "PingCompletedCallback" is not getting executed.
Thanx
There's a class for that;
MSDN Article on System.Net.NetworkInformation.Ping
GeekPedia article on asynchronous ping
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.
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:
How to get whois information of a domain name in my program?
Parse whois answer
You could use the Ping class - here's all the info you need on MSDN
精彩评论