22using Demo . HttpServices ;
33using System ;
44using System . Diagnostics ;
5- using System . Net . Http ;
5+ using System . Linq ;
6+ using System . Net ;
7+ using System . Threading ;
68using System . Threading . Tasks ;
79using WebApiClient ;
810using WebApiClient . Parameterables ;
@@ -11,14 +13,40 @@ namespace Demo
1113{
1214 class Program
1315 {
16+ private static long totalProxyCount = 0 ;
17+ private static int completedProxyCount = 0 ;
18+
1419 static void Main ( string [ ] args )
1520 {
1621 HttpServer . Start ( 9999 ) ;
17- Program . RunIUserApi ( 1 ) ;
22+ Program . RunIUserApi ( 1 ) . ContinueWith ( t => ScanProxy ( ) ) ;
1823 Console . ReadLine ( ) ;
1924 }
2025
21- static async void RunIUserApi ( int loop = 1 )
26+ /// <summary>
27+ /// 扫描代理ip
28+ /// </summary>
29+ static async void ScanProxy ( )
30+ {
31+ var proxys = HttpProxy . Range ( IPAddress . Parse ( "221.122.13.1" ) , 8080 , 9999 ) . ToArray ( ) ;
32+ var target = new Uri ( "http://www.baidu.com" ) ;
33+ var tasks = proxys . Select ( async p =>
34+ {
35+ Interlocked . Increment ( ref totalProxyCount ) ;
36+ var state = await ProxyValidator . ValidateAsync ( p , target , TimeSpan . FromMilliseconds ( 500d ) ) ;
37+ if ( state == HttpStatusCode . OK )
38+ {
39+ Console . WriteLine ( $ "扫描到代理服务:{ p . Host } :{ p . Port } ") ;
40+ }
41+
42+ var completed = Interlocked . Increment ( ref completedProxyCount ) ;
43+ Console . Title = $ "扫描进度:{ completed } /{ Interlocked . Read ( ref totalProxyCount ) } ";
44+ } ) ;
45+ await Task . WhenAll ( tasks ) ;
46+ }
47+
48+
49+ static async Task RunIUserApi ( int loop = 1 )
2250 {
2351 var watch = new Stopwatch ( ) ;
2452 watch . Start ( ) ;
0 commit comments