如何“ping”域名?
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
有一个类可以做到这一点;
有关 System.Net.NetworkInformation.Ping 的 MSDN 文章
关于异步 ping 的 GeekPedia 文章
There's a class for that;
MSDN Article on System.Net.NetworkInformation.Ping
GeekPedia article on asynchronous ping
使用 System.Net.NetworkInformation.Ping 类,
它未经测试,但这是一般的想法。
Using the System.Net.NetworkInformation.Ping class,
It's untested, but that's the general idea.
我认为 ping 域名不会以可靠的方式告诉您任何相关信息。
域名可以注册,但不能连接到服务器。即使域名已注册,Ping 请求也会失败。
服务器可以完全运行,但可以配置为不响应 ping 请求。即使域已注册并在服务器上运行,Ping 请求也会失败。
您想做什么 - 查明域名是否已注册、域名是否有效、网站/邮件服务器是否正常工作……?
对于前两个,我建议使用
whois
服务。例如,请参阅以下 C# 相关问题:
如何在我的程序中获取域名的whois信息?
解析 whois 答案
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
您可以使用 Ping 类 - 这是您需要的所有信息
You could use the Ping class - here's all the info you need on MSDN