Ejemplo n.º 1
0
 private void CheckProxyServers()
 {
     try
     {
         Loading = true;
         ProxyServers.Clear();
         var testTargetUri = TestTargetUri;
         if (testTargetUri != null)
         {
             var route = ProxyClient.CreateRoute(LocalProxy);
             foreach (var hostEndPoint in ProxyPageScanner.ScanPage(ProxyPage.PageUri, ProxyPage.ParseAsText, ProxyPage.HostPortEx, route, testTargetUri))
             {
                 var ipEndPoint = hostEndPoint.IPEndPoint;
                 if (ipEndPoint == null)
                 {
                     continue;
                 }
                 var location = Geolocation.Locate(ipEndPoint.Address, route);
                 var p        = ProxyAnalyzer.MeasurePerformance(route, testTargetUri);
                 if (p == null)
                 {
                     continue;
                 }
                 var proxy = new Proxy(hostEndPoint, location, (int)p.Ping.TotalMilliseconds, (int)(p.DownloadSpeed / 1024));
                 ProxyServers.Add(proxy);
             }
         }
     }
     finally
     {
         Loading = false;
     }
 }
        private void DoAutoAddFreeProxy(FreeProxySource src)
        {
            foreach (var path in src.Paths)
            {
                RestClient client = new RestClient(src.Host);

                var req = client.TakeRequest(path);
                req.Node.Method = Method.GET;
                req.Node.AddHeader("User-Agent", "Mozilla / 5.0(Windows NT 10.0; WOW64; rv: 63.0) Gecko / 20100101 Firefox / 63.0");
                req.Node.AddHeader("Accept", "text / html,application / xhtml + xml,application / xml; q = 0.9,*/*;q=0.8");
                req.Node.AddHeader("Accept-Language", "zh-TW,zh;q=0.8,en-US;q=0.5,en;q=0.3");
                req.Node.AddHeader("Accept-Encoding", "gzip, deflate");


                var dReq = ((dynamic)req);
                //dReq.Parameter.url = HttpUtility.UrlPathEncode(longUrl);
                var rlt      = client.Execute(req);
                var htmlText = encoding.GetString(rlt.RawBytes);
                var matchs   = src.ContentRegex.Matches(htmlText);
                foreach (Match match in matchs)
                {
                    if (match.Success)
                    {
                        var ip = match.Groups[1].Value;
                        if (string.IsNullOrEmpty(ip))
                        {
                            continue;
                        }
                        if (!string.IsNullOrEmpty(src.ReplaceDotString))
                        {
                            ip = ip.Replace(src.ReplaceDotString, "");
                        }
                        if (!string.IsNullOrEmpty(src.ReplaceDotString))
                        {
                            ip = ip.Replace(src.ReplaceDotString, ".");
                        }
                        var port     = Convert.ToInt32(match.Groups[2].Value, src.IsHexPortType ? 16 : 10);
                        var newProxy = new WebProxyServerEntity()
                        {
                            FailedNum = 0, IP = ip, Port = port
                        };
                        if (this.ProxyServers.Find(pxy => pxy.IP == newProxy.IP) == null)
                        {
                            if (CheckProxy(newProxy))
                            {
                                ProxyServers.Add(newProxy);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void GetProxyServers()
        {
            var proxyPage = RetrievePage("http://www.sslproxies.org/");
            // Generate structured document
            var proxyParser = new HtmlParser();
            var proxyDoc    = proxyParser.Parse(proxyPage);
            // Get proxy list
            var proxyIp   = proxyDoc.QuerySelectorAll("table.fpltable > tbody > tr > td:nth-child(1)");
            var proxyPort = proxyDoc.QuerySelectorAll("table.fpltable > tbody > tr > td:nth-child(2)");

            for (int i = 0; i < proxyIp.Length; i++)
            {
                ProxyServers.Add(new ProxyServer
                {
                    Ip   = proxyIp[i].TextContent,
                    Port = proxyPort[i].TextContent
                });
            }
            CurrentProxy = ProxyServers.First();
        }