gpt4 book ai didi

c# - Pinging 域 C#

转载 作者:太空宇宙 更新时间:2023-11-03 16:36:45 24 4
gpt4 key购买 nike

尝试 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);
}

感谢任何帮助:-)

最佳答案

嘿,我运行了这段代码并且它有效,(输入 worng 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";
}


}

关于c# - Pinging 域 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8873701/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com