I need to know how to check if an IP with Port is working to connect to. Port is 7171, and I'm using Visual Studio C# Express 2010 .NET.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
To check ip is working you can do a ping using your code and opening cmd from your code.
You can check if port is free assuming you are using tcpclint :
int port = 456; //<--- This is your value
bool isAvailable = true;
IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
TcpConnectionInformation[] tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections();
foreach (TcpConnectionInformation tcpi in tcpConnInfoArray)
{
if (tcpi.LocalEndPoint.Port==port)
{
isAvailable = false;
break;
}
}