Ping 域 C#

发布于 2024-12-27 07:06:36 字数 994 浏览 1 评论 0原文

尝试 ping 域名并查看是否收到响应代码以指示其是否已注册。从以下代码中获得持续的积极结果 - 有什么想法吗?

public static string Check(string keyword)
    {
        Ping pingSender = new Ping();
        PingOptions options = new PingOptions();

        // Use the default Ttl value which is 128,
        // but change the fragmentation behavior.
        options.DontFragment = true;

        // Create a buffer of 32 bytes of data to be transmitted.
        string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
        byte[] buffer = Encoding.ASCII.GetBytes(data);
        int timeout = 120;
        PingReply reply = pingSender.Send(keyword, timeout, buffer, options);
        if (reply.Status == IPStatus.Success)
        {

            return "found";
        }
        else
        {
            return "not found";
        }
    }


    private void hunt_Click(object sender, EventArgs e)
    {
        string keyword = txtKeyword.Text;
        txtOutput.Text = Check(keyword);
    }

如有任何帮助,我们将不胜感激:-)

trying to ping a domain and see if i get a response code to get a indication if its registered. getting constant positive results from the following code - any ideas?

public static string Check(string keyword)
    {
        Ping pingSender = new Ping();
        PingOptions options = new PingOptions();

        // Use the default Ttl value which is 128,
        // but change the fragmentation behavior.
        options.DontFragment = true;

        // Create a buffer of 32 bytes of data to be transmitted.
        string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
        byte[] buffer = Encoding.ASCII.GetBytes(data);
        int timeout = 120;
        PingReply reply = pingSender.Send(keyword, timeout, buffer, options);
        if (reply.Status == IPStatus.Success)
        {

            return "found";
        }
        else
        {
            return "not found";
        }
    }


    private void hunt_Click(object sender, EventArgs e)
    {
        string keyword = txtKeyword.Text;
        txtOutput.Text = Check(keyword);
    }

any help is appreciated :-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

倾`听者〃 2025-01-03 07:06:36

嘿,我运行了这段代码,它可以工作,(输入磨损的 IP 或 DNS 时会抛出异常)为什么不使用这个重载?

       public static string Check(string keyword)
         {
        Ping pingSender = new Ping();
        //PingOptions options = new PingOptions();

        // Use the default Ttl value which is 128, 
        // but change the fragmentation behavior. 
       // options.DontFragment = true;

        // Create a buffer of 32 bytes of data to be transmitted. 
        //string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
        // byte[] buffer = Encoding.ASCII.GetBytes(data);
        // int timeout = 120;
        try
        {
            PingReply reply = pingSender.Send(keyword);
            return "found";
        }
        catch
        {
            return "not found";
        }


    }

hey i ran this code and it works, (exception is thrown when worng IP or DNS is entered) why not use this overload?

       public static string Check(string keyword)
         {
        Ping pingSender = new Ping();
        //PingOptions options = new PingOptions();

        // Use the default Ttl value which is 128, 
        // but change the fragmentation behavior. 
       // options.DontFragment = true;

        // Create a buffer of 32 bytes of data to be transmitted. 
        //string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
        // byte[] buffer = Encoding.ASCII.GetBytes(data);
        // int timeout = 120;
        try
        {
            PingReply reply = pingSender.Send(keyword);
            return "found";
        }
        catch
        {
            return "not found";
        }


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