Exemple #1
0
        public List <ProxyModel> Parse(string data)
        {
            List <ProxyModel> ls       = new List <ProxyModel>();
            HtmlDocument      document = new HtmlDocument();

            document.LoadHtml(data);
            var tbodys = document.DocumentNode.SelectNodes("//*[@id=\"list\"]/table/tbody").ToList();

            foreach (var tbody in tbodys)
            {
                var tr = tbody.ChildNodes.Where(a => a.Name == "tr").ToList();
                foreach (var item in tr)
                {
                    ProxyModel model = new ProxyModel();
                    var        tds   = item.ChildNodes.Where(a => a.Name == "td").ToList();
                    var        ip    = tds[0].InnerHtml;
                    int.TryParse(tds[1].InnerHtml, out int port);
                    var state   = tds[2].InnerHtml;
                    var type    = tds[3].InnerHtml;
                    var address = tds[4].InnerHtml;
                    var timeout = tds[5].InnerHtml;
                    model.Ip      = ip;
                    model.Port    = port;
                    model.State   = state;
                    model.Type    = type;
                    model.Address = address;
                    model.TimeOut = timeout;
                    ls.Add(model);
                }
            }
            return(ls);
        }
Exemple #2
0
 public static async Task <ProxyModel> ProxyCheckAsync1(ProxyModel model)
 {
     try
     {
         ServicePointManager.DefaultConnectionLimit = 200;
         Stopwatch stopwatch = new Stopwatch();
         stopwatch.Start();
         HttpWebRequest request = (HttpWebRequest)WebRequest.Create(SpeedUrl);
         var            proxy   = new WebProxy(model.Ip, model.Port);
         request.Timeout   = 3000;
         request.Proxy     = proxy;
         request.KeepAlive = false;
         using (var response = await request.GetResponseAsync())
             using (var responseStream = response.GetResponseStream())
             {
                 stopwatch.Stop();
                 model.TimeOut = stopwatch.ElapsedMilliseconds + "毫秒";
                 return(model);
             }
     }
     catch (Exception e)
     {
         return(null);
     }
 }
Exemple #3
0
        public static async Task <ProxyModel> ProxyCheckAsync(ProxyModel model)
        {
            //try
            //{
            //    Console.WriteLine($"开始测试 {model.Ip}:{model.Port}");
            //    Stopwatch stopwatch = new Stopwatch();
            //    stopwatch.Start();
            //    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(SpeedUrl);
            //    var proxy = new WebProxy(model.Ip, model.Port);
            //    request.Timeout = 3000;
            //    request.Proxy = proxy;
            //    request.KeepAlive = false;
            //    using (var response = request.GetResponse())
            //    using (var responseStream = response.GetResponseStream())
            //    {
            //        stopwatch.Stop();
            //        model.TimeOut = stopwatch.ElapsedMilliseconds + "毫秒";
            //        Console.WriteLine($"结束测试 {model.Ip}:{model.Port}");
            //        return true;
            //    }
            //}
            //catch (Exception e)
            //{
            //    LogManager log = new LogManager();
            //    log.Info($"{model.Ip}:{model.Port}:{e}");
            //    Console.WriteLine($"{model.Ip}:{model.Port}:{e.Message}");
            //    return false;
            //}
            try
            {
                Console.WriteLine($"开始测试 {model.Ip}:{model.Port}");
                HttpClientHandler handler = new HttpClientHandler();
                handler.UseProxy = true;

                HttpClient client = new HttpClient(handler, false);
                client.Timeout = TimeSpan.FromSeconds(5);
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                var proxy = new WebProxy(model.Ip, model.Port);
                proxy.Credentials = CredentialCache.DefaultCredentials;

                handler.Proxy                 = proxy;
                handler.PreAuthenticate       = true;
                handler.UseDefaultCredentials = false;
                var res = await client.GetAsync(SpeedUrl);

                stopwatch.Stop();
                model.TimeOut = stopwatch.ElapsedMilliseconds + "毫秒";
                Console.WriteLine($"结束测试 {model.Ip}:{model.Port}");
                model.Usable = true;
                return(model);
            }
            catch (Exception e)
            {
                LogManager log = new LogManager();
                log.Info($"{model.Ip}:{model.Port}:{e}");
                Console.WriteLine($"{model.Ip}:{model.Port}:{e.Message}");
                return(model);
            }
        }
Exemple #4
0
        public List <ProxyModel> Parse(string data)
        {
            List <ProxyModel> ls       = new List <ProxyModel>();
            HtmlDocument      document = new HtmlDocument();

            document.LoadHtml(data);
            var tbodys = document.DocumentNode.SelectNodes("//table[@class=\"layui-table\"]/tbody").ToList();

            foreach (var tbody in tbodys)
            {
                var tr = tbody.ChildNodes.Where(a => a.Name == "tr").ToList();
                foreach (var item in tr)
                {
                    var tds     = item.ChildNodes.Where(a => a.Name == "td").ToList();
                    var ip      = tds[0].InnerHtml;
                    var port    = tds[1].InnerHtml;
                    var address = tds[2].InnerHtml + tds[3].InnerHtml;
                    ip      = Regex.Replace(ip, "[\r\n\t]*", "");
                    port    = Regex.Replace(port, "[\r\n\t]*", "");
                    address = Regex.Replace(address, "[\r\n\t ]*", "");
                    int.TryParse(port, out var porti);
                    ProxyModel model = new ProxyModel();
                    model.Ip      = ip;
                    model.Port    = porti;
                    model.Address = address;
                    ls.Add(model);
                }
            }
            return(ls);
        }
Exemple #5
0
        public List <ProxyModel> Parse(string data)
        {
            List <ProxyModel> list = new List <ProxyModel>();

            HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
            document.LoadHtml(data);
            var ip_list = document.DocumentNode.SelectNodes("//*[@id=\"ip_list\"]");
            var datas   = ip_list.Nodes().ToList().Where(a => a.Name == "tr").ToList();

            datas.RemoveAt(0);
            foreach (var item in datas)
            {
                var    itemDatas = item.ChildNodes.Nodes().ToList();
                string ip;
                int    port;
                string address = string.Empty;
                string state;
                string type;
                string timeout;
                if (itemDatas.Count == 16)
                {
                    ip = itemDatas[1].InnerHtml;                                                                      //0
                    int.TryParse(itemDatas[2].InnerHtml, out port);                                                   //1
                    address = itemDatas[4].InnerHtml;                                                                 //
                    state   = itemDatas[6].InnerHtml;                                                                 //3
                    type    = itemDatas[7].InnerHtml;                                                                 //4
                    timeout = itemDatas[9].Attributes.Where(a => a.Name == "title").ToList().SingleOrDefault().Value; //
                }
                else
                {
                    ip = itemDatas[0].InnerHtml;//0
                    int.TryParse(itemDatas[1].InnerHtml, out port);
                    //address = "";//
                    state   = itemDatas[3].InnerHtml;                                                                 //3
                    type    = itemDatas[4].InnerHtml;                                                                 //4
                    timeout = itemDatas[9].Attributes.Where(a => a.Name == "title").ToList().SingleOrDefault().Value; //
                }
                ProxyModel model = new ProxyModel();
                model.Address = address;
                model.Ip      = ip;
                model.Port    = port;
                model.State   = state;
                model.TimeOut = timeout;
                model.Type    = type;
                list.Add(model);
            }
            return(list);
        }