示例#1
0
        /// <summary>
        /// 验证一个端口号是否被使用
        /// </summary>
        /// <param name="ipaddr">IP对象</param>
        /// <param name="port">需要验证的端口号</param>
        /// <returns>如果被使用返回true,否则返回false</returns>
        public static bool PortAvailable(this IPAddress ipaddr, int port)
        {
            List <int> tcpPorts = null;
            List <int> udpPorts = null;
            List <int> ipPorts  = null;
            var        allports = IPAddressEx.GetUsedPorts(out tcpPorts, out udpPorts, out ipPorts);

            return(allports.Contains(port));
        }
示例#2
0
        /// <summary>
        /// 获取已使用的端口号
        /// </summary>
        /// <returns>当前所有已使用端口号集合</returns>
        public static List <int> GetUsedPorts()
        {
            List <int> tcpPorts, udpPorts, ipPorts;

            return(IPAddressEx.GetUsedPorts(out tcpPorts, out udpPorts, out ipPorts));
        }