正在检查带有端口的ip是否可用
本文关键字:ip 是否 检查 | 更新日期: 2023-09-27 18:21:12
我需要知道如何检查带端口的IP是否可以连接。端口是7171,我使用的是Visual Studio C#Express 2010.NET。
要检查ip是否工作,您可以使用代码执行ping并从代码中打开cmd。
您可以检查端口是否空闲,假设您使用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;
}
}