创建Windows应用程序以检查与少数服务器的连接。如何检查天气是否存在与远程ip上指定端口的连接?如何检查远程端口是否打开
是否有任何Windows内置命令来检查远程端口(命令行)?
检查前不知道天气端口是TCP还是UDP端口。怎么可能。
在此先感谢
创建Windows应用程序以检查与少数服务器的连接。如何检查天气是否存在与远程ip上指定端口的连接?如何检查远程端口是否打开
是否有任何Windows内置命令来检查远程端口(命令行)?
检查前不知道天气端口是TCP还是UDP端口。怎么可能。
在此先感谢
从我的(德国)博客:enter link description here
更新:该工具支持UDP端口和多端口平现在太。
如果端口打开,它将返回true。这是老式的代码(没有TPL),但它的工作原理。
var result = false;
using (var client = new TcpClient())
{
try
{
client.ReceiveTimeout = timeout * 1000;
client.SendTimeout = timeout * 1000;
var asyncResult = client.BeginConnect(host, port, null, null);
var waitHandle = asyncResult.AsyncWaitHandle;
try
{
if (!asyncResult.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(timeout), false))
{
// wait handle didn't came back in time
client.Close();
}
else
{
// The result was positiv
result = client.Connected;
}
// ensure the ending-call
client.EndConnect(asyncResult);
}
finally
{
// Ensure to close the wait handle.
waitHandle.Close();
}
}
catch
{
}
}
return result;
退房:http://serverfault.com/questions/309357/ping-a-specific-port – DonBoitnott 2014-10-09 11:46:25