示例#1
0
        private static IPEndPoint GetEndpointWithFreeRandomPort(string ip = "0.0.0.0")
        {
            for (int port = 50000; port < 65535; port++)
            {
                var ipPort = new IPEndPoint(IPAddress.Parse(ip), port);
                if (IpEndpointTools.IpEndpointIsAvailableForListening(ipPort) && !CertConfigCmd.IpPortIsPresentInConfig(ipPort))
                {
                    return(ipPort);
                }
            }

            return(null);
        }
示例#2
0
        public static IPEndPoint[] GetIpEndPoints(string thumbprint = null)
        {
            var result  = Show(throwExcepton: true);
            var pattern = string.Format(@"\s+IP:port\s+:\s+(\S+?)\s+Certificate Hash\s+:\s+{0}\s+",
                                        string.IsNullOrEmpty(thumbprint) ? @"\S+" : thumbprint);
            var matches = Regex.Matches(result.Output, pattern,
                                        RegexOptions.IgnoreCase | RegexOptions.CultureInvariant |
                                        RegexOptions.Singleline);

            var endPoints = matches.Cast <Match>().Select(match => IpEndpointTools.ParseIpEndPoint(match.Groups[1].Value)).ToArray();

            return(endPoints);
        }