/// <summary>
/// 检测端口是否被占用
/// </summary>
/// <param name="port"></param>
/// <returns></returns>
public bool PortCheck(int port)
{
    bool flag = false;

    IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
    IPEndPoint[] ipEndPoints = ipProperties.GetActiveTcpListeners();//获取所有的监听连接

    foreach (IPEndPoint endPoint in ipEndPoints)
    {
        System.Diagnostics.Debug.WriteLine(endPoint.Port);
        if (endPoint.Port == port)
        {
            flag = true;
        }
    }

    return flag;
}

也可以 netstat -a 查看当前活动端口

 

转载自 : http://www.cnblogs.com/bayonetxxx/archive/2009/07/22/1498747.html

相关文章:

  • 2022-01-19
  • 2021-07-11
  • 2022-01-23
  • 2021-12-25
  • 2022-01-02
  • 2022-12-23
  • 2022-02-01
  • 2021-12-15
猜你喜欢
  • 2021-12-04
  • 2021-11-13
  • 2022-01-24
  • 2022-01-13
  • 2021-12-19
  • 2021-12-31
相关资源
相似解决方案