コード例 #1
0
        public List <IDrummerProxy> Parse()
        {
            var proxies = new List <IDrummerProxy>();

            foreach (var textLine in source)
            {
                var cleanText = textLine.Trim().ToLowerInvariant();
                cleanText = Regex.Replace(cleanText, @"\s+", ":");

                var matches = Regex.Matches(cleanText, IpAddressRegex, RegexOptions.IgnoreCase);

                foreach (Match ipAddress in matches)
                {
                    var proxyParts = ipAddress.Value.Split(':');
                    if (proxyParts.Length < 2)
                    {
                        continue;
                    }
                    var drummerProxy = new DrummerProxy(proxyParts[0], int.Parse(proxyParts[1]));
                    proxies.Add(drummerProxy);
                }
            }
            return(proxies);
        }
コード例 #2
0
        public async Task <IList <IDrummerProxy> > GetProxiesAsync()
        {
            var proxies = new List <IDrummerProxy>();

            try
            {
                using (var client = new HttpClient())
                {
                    using (var response = await client.GetAsync(new Uri(proxySourceUrl)))
                    {
                        using (var content = response.Content)
                        {
                            var htmlString = await content.ReadAsStringAsync();

                            var matches = Regex.Matches(htmlString, proxyPattern);
                            foreach (Match match in matches)
                            {
                                if (!match.Success)
                                {
                                    continue;
                                }
                                var proxy        = match.Value;
                                var proxyParts   = proxy.Split(':');
                                var drummerProxy = new DrummerProxy(proxyParts[0], int.Parse(proxyParts[1]));
                                proxies.Add(drummerProxy);
                            }
                        }
                    }
                }
            }
            catch
            {
            }

            return(proxies);
        }