コード例 #1
0
ファイル: ADSLIP.cs プロジェクト: jx-qyj/Tools
        /// <summary>
        /// 代理Ip校验
        /// </summary>
        /// <param name="Ip">待校验代理IP</param>
        /// <param name="CheckUrl">检验地址</param>
        /// <returns></returns>
        public static bool CheckIp(String Ip, String CheckUrl = "http://2017.ip138.com/ic.asp")
        {
            HttpHelper helper = new HttpHelper();
            HttpItem   item   = new HttpItem();
            HttpResult result = new HttpResult();

            item.URL              = CheckUrl;
            item.ProxyIp          = Ip;
            item.Timeout          = 5000;
            item.ReadWriteTimeout = 10000;
            //item.UserAgent = UAPool.GetRandomUA();
            item.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.04";

            String html = helper.GetHtml(item).Html;

            return(html.Contains("您的IP是"));
        }
コード例 #2
0
ファイル: HttpMethod.cs プロジェクト: jx-qyj/Tools
        /// <summary>
        /// 返回重定向地址
        /// </summary>
        /// <param name="ReditUrl">重定向地址</param>
        /// <param name="Url">目标地址</param>
        /// <param name="ip">代理Ip</param>
        /// <param name="TimeOut">超时时间</param>
        /// <param name="UA">UA</param>
        /// <returns>网页源代码</returns>
        public static String FastGetMethod(out String ReditUrl, String Url, String ip = null, int TimeOut = 5000, String UA = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36")
        {
            HttpHelper helper = new HttpHelper();
            HttpItem   item   = new HttpItem();
            HttpResult result = new HttpResult();

            item.Timeout = TimeOut;
            if (String.IsNullOrEmpty(UA))
            {
                item.UserAgent = new UAPool().GetRandomUA();
            }
            else
            {
                item.UserAgent = UA;
            }
            item.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
            item.Accept      = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
            item.URL         = Url;
            if (!String.IsNullOrEmpty(ip))
            {
                item.ProxyIp          = ip;
                item.Timeout          = 8000;
                item.ReadWriteTimeout = 10000;
            }
            else
            {
                //  item.Ip = ip;
            }
            // info.Referer = String.Empty;
            result = helper.GetHtml(item);
            try
            {
                ReditUrl = result.Header["Location"].ToString();
            }
            catch
            {
                ReditUrl = String.Empty;
            }
            return(result.Html);
        }
コード例 #3
0
ファイル: HttpMethod.cs プロジェクト: jx-qyj/Tools
        /// <summary>
        /// 校验IP
        /// </summary>
        /// <param name="Ip">待校验的Ip地址</param>
        /// <param name="CheckUrl">校检地址</param>
        /// <returns></returns>
        public static bool CheckIp(String Ip, String CheckUrl = "http://2017.ip138.com/ic.asp")
        {
            HttpHelper helper = new HttpHelper();
            HttpItem   item   = new HttpItem();
            HttpResult result = new HttpResult();

            item.URL              = CheckUrl;
            item.ProxyIp          = Ip;
            item.Timeout          = 5000;
            item.ReadWriteTimeout = 8000;
            //item.UserAgent = UAPool.GetRandomUA();
            item.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.04";


            String html = helper.GetHtml(item).Html;

            if (string.IsNullOrEmpty(Ip))
            {
                return(!String.IsNullOrEmpty(html));
            }
            string Ips = Ip.Substring(0, Ip.IndexOf(":"));

            return(html.Contains(Ips));
        }
コード例 #4
0
        /// <summary>
        /// 验Ip线程函数
        /// </summary>
        /// <param name="index">代理ip地址在APIList中的索引</param>
        /// <param name="checknum">验ip线程数</param>
        public static void IPCheckFunc(String api = "", int index = 1, int checknum = 100, int limit = 1000, int delay = 5000)
        {
            String API_Url = String.IsNullOrEmpty(api)?String.Format(API_Url_List[index], limit):api;
            var    ips     = HttpMethod.InputApi(API_Url);

            Thread[] tarr = new Thread[checknum];
            Task.Factory.StartNew(() =>
            {
                while (IPCheckStack.Count < 500)
                {
                    if (ips.Count == 0)
                    {
                        ips = HttpMethod.InputApi(API_Url);
                    }
                    Thread.Sleep(delay);
                }
            });


            for (int i = 0; i < checknum; i++)
            {
                tarr[i] = new Thread(new ThreadStart(delegate {
                    String ip             = String.Empty;
                    HttpHelper helper     = new HttpHelper();
                    HttpItem item         = new HttpItem();
                    HttpResult result     = new HttpResult();
                    item.URL              = "http://2017.ip138.com/ic.asp";
                    item.Timeout          = 6000;
                    item.ReadWriteTimeout = 8000;
                    item.UserAgent        = "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.04";
                    String Ips            = String.Empty;
                    while (true)
                    {
                        if (IPCheckStack.Count < 500)
                        {
                            if (ips.TryPop(out ip))
                            {
                                item.ProxyIp = ip;
                                try
                                {
                                    if (helper.GetHtml(item).Html.Contains(ip.Substring(0, ip.IndexOf(":"))))
                                    {
                                        IPCheckStack.Push(ip);
                                    }
                                }
                                catch
                                {
                                }
                            }
                            else
                            {
                                Thread.Sleep(1000);
                            }
                        }
                        else
                        {
                            Thread.Sleep(5000);
                        }
                    }
                }));
                tarr[i].IsBackground = true;
                tarr[i].Start();
            }
        }