public void RangeTest() { var proxys = HttpProxy.Range(IPAddress.Parse("221.122.0.1"), 8080, 5).ToArray(); Assert.True(proxys.Length == 5); Assert.True(proxys.First().Host == "221.122.0.1"); Assert.True(proxys.Last().Host == "221.122.0.5"); }
/// <summary> /// 扫描代理ip /// </summary> static async void ScanProxy() { var timeout = TimeSpan.FromMilliseconds(500d); var target = new Uri("http://www.baidu.com"); var proxyValidators = HttpProxy .Range(IPAddress.Parse("221.122.13.1"), 8080, 9999) .Select(p => p.ToValidator()); var tasks = proxyValidators.Select(async v => { Interlocked.Increment(ref totalProxyCount); if (await v.ValidateAsync(target, timeout) == HttpStatusCode.OK) { Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss.fff")}:扫描到代理服务:{v}"); } var completed = Interlocked.Increment(ref completedProxyCount); Console.Title = $"代理扫描进度:{completed}/{Interlocked.Read(ref totalProxyCount)}"; }); await Task.WhenAll(tasks); }