如何“ping”域名?

发布于 2024-09-01 21:56:23 字数 288 浏览 1 评论 0原文

在代码中我想验证域名。

例如:“域名.com”。

我怎样才能在 C# 中做到这一点。

我致力于 MSDN 解决方案。 (第二个解决方案)。

但是“PingCompletedCallback”没有被执行。

谢谢

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

剩一世无双 2024-09-08 21:56:23

使用 System.Net.NetworkInformation.Ping 类,

using System.Net.NetworkInformation;

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

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

它未经测试,但这是一般的想法。

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.

无法回应 2024-09-08 21:56:23

我认为 ping 域名不会以可靠的方式告诉您任何相关信息。

  • 域名可以注册,但不能连接到服务器。即使域名已注册,Ping 请求也会失败。

  • 服务器可以完全运行,但可以配置为不响应 ping 请求。即使域已注册并在服务器上运行,Ping 请求也会失败。

您想做什么 - 查明域名是否已注册、域名是否有效、网站/邮件服务器是否正常工作……?

对于前两个,我建议使用 whois 服务。
例如,请参阅以下 C# 相关问题:

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:

眼泪淡了忧伤 2024-09-08 21:56:23

您可以使用 Ping 类 - 这是您需要的所有信息

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文