ping域C#
尝试ping一个域,看看我是否得到了一个响应代码,以获得一个指示,如果它已注册。从以下代码中获得持续的积极结果-有什么想法吗ping域C#,c#,web,ping,C#,Web,Ping,尝试ping一个域,看看我是否得到了一个响应代码,以获得一个指示,如果它已注册。从以下代码中获得持续的积极结果-有什么想法吗 public static string Check(string keyword) { Ping pingSender = new Ping(); PingOptions options = new PingOptions(); // Use the default Ttl value which is 128,
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";
}
}
嘿,我运行了这段代码,它运行正常,(当输入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";
}
}
你能写下你试图执行它的关键字吗?可能与我尝试在域“www.goosdfdsgle.com”中运行上述代码的情况相同,并引发套接字异常“这通常是主机名解析期间的临时错误,意味着本地服务器没有收到权威服务器的响应”。似乎是正确的行为。你能写下你试图执行它的关键字吗?可能是重复的,我尝试在域“www.goosdfdsgle.com”中运行上述代码,并引发套接字异常“这通常是主机名解析过程中的临时错误,意味着本地服务器没有收到来自权威服务器的响应”。这似乎是正确的行为。