static bool CheckPortAvailable(int port)
        {
            bool isAvailable = true;
            IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();

            foreach (var tcplisten in ipGlobalProperties.GetActiveTcpListeners())
            {
                if (tcplisten.Port == port)
                {
                    isAvailable = false;
                    break;
                }
            }
            if (isAvailable)
            {
                foreach (var udplisten in ipGlobalProperties.GetActiveUdpListeners())
                {
                    if (udplisten.Port == port)
                    {
                        isAvailable = false;
                        break;
                    }
                }
            }
            return isAvailable;
        }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-20
  • 2022-12-23
  • 2022-02-07
  • 2021-08-15
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2021-10-27
  • 2021-09-04
  • 2022-01-19
  • 2021-11-09
相关资源
相似解决方案