public void AddRange(ProxyList collection) { this.Capacity += collection.Count; foreach (var proxy in collection) { AddUnique(proxy); } }
public static void WriteFile(string filePath, ProxyList proxies) { var output = new StreamWriter(filePath); foreach (var proxy in proxies) { output.WriteLine("{0}", proxy.Address); } }
public static ProxyList ParseString(string content) { var proxies = new ProxyList(); var regex = new Regex(@"(\d+\.\d+\.\d+\.\d+)(?:\:|\s+)(\d+)"); foreach (Match match in regex.Matches(content)) { proxies.Add(new WebProxy(match.Groups[1].Value, int.Parse(match.Groups[2].Value))); } return(proxies); }
public static async Task <ProxyList> ParseFreeProxyListAsync() { ProxyList proxies = new ProxyList(); string content = await GetPageAsync("http://free-proxy-list.net/"); var regex = new Regex(@"<td>(\d+\.\d+\.\d+\.\d+)</td><td>(\d+)</td>"); foreach (Match match in regex.Matches(content)) { proxies.Add(new WebProxy(match.Groups[1].Value, int.Parse(match.Groups[2].Value))); } return(proxies); }
public static async Task <ProxyList> ParseHideMyIpAsync() { ProxyList proxies = new ProxyList(); string content = await GetPageAsync("http://www.hide-my-ip.com/proxylist.shtml"); var regex = new Regex(@"{""i"":""(\d+\.\d+\.\d+\.\d+)"",""p"":""(\d+)"""); foreach (Match match in regex.Matches(content)) { proxies.Add(new WebProxy(match.Groups[1].Value, int.Parse(match.Groups[2].Value))); } return(proxies); }
public ProxyList Uniqued() { var result = new ProxyList(); var urls = new List <Uri>(); foreach (WebProxy proxy in this) { if (!urls.Contains(proxy.Address)) { urls.Add(proxy.Address); result.Add(proxy); } } return(result); }
public static async Task <ProxyList> ParseAllAsync() { var proxies = new ProxyList(); var tasks = new List <Task <ProxyList> >(); tasks.Add(ParseUsProxyAsync()); tasks.Add(ParseFreeProxyListAsync()); foreach (var task in tasks) { proxies.AddRange(await task); } return(proxies); }
public async Task CheckAsync(ProxyList proxies, int connections, TimeSpan timeout) { var semaphore = new SemaphoreSlim(connections); var tasks = proxies.Select(async proxy => { await semaphore.WaitAsync(); try { var handler = new HttpClientHandler() { Proxy = proxy, UseProxy = true }; var http = new HttpClient(handler) { Timeout = timeout }; http.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:49.0) Gecko/20100101 Firefox/49.0"); Console.WriteLine("Check {0}", proxy.Address); HttpResponseMessage responce = await http.GetAsync("http://google.com"); Console.WriteLine("Status {0}: {1}", proxy.Address, responce.StatusCode); if (responce.IsSuccessStatusCode) { ProxyCheckedSuccessfull(this, proxy); } } catch (Exception e) { Console.WriteLine(e.Message); } finally { ProxyChecked(this, proxy); semaphore.Release(); } }); await Task.WhenAll(tasks); }