Пример #1
0
        public static string getProxyHost(int cacheSec = 300)
        {
            string result = "";

            if (_MemoryCache.TryGetValue(keyHttpProxy, out result))
            {
                //  if(TestProxy(result))
                return(result);
            }

            string host = getAvaliableHost();

            if (string.IsNullOrEmpty(host))
            {
                return("");
            }


            MemoryCacheEntryOptions options = new MemoryCacheEntryOptions();

            options.AbsoluteExpiration = DateTime.Now.AddSeconds(cacheSec);
            _MemoryCache.Set(keyHttpProxy, host, options);

            var platform = _stPlantSources.Peek();

            NLogUtil.InfoTxt($"Find New Proxy Host:{platform}_{host}");
            return(host);
        }
Пример #2
0
        /// <summary>
        ///  贝壳 http://h.beikeruanjian.com/get/ jackysong@edifier
        /// </summary>
        public static bool AddBeiKeHost()
        {
            bool       result     = true;
            HttpClient httpClient = new HttpClient();
            var        rep        = httpClient.GetAsync(BeiKeUrl);

            rep.Wait();
            //  rep.Status == System.Threading.Tasks.TaskStatus.
            var     json = rep.Result.Content.ReadAsStringAsync();
            JObject j    = null;

            try
            {
                j = JObject.Parse(json.Result);
                var status = j["status"].ToString();
                if (status == "success")
                {
                    var v = j["data"][0]["ipport"].ToString();
                    _proxyHosts.Push(v);
                }
                else
                {
                    result = false;
                }
            }
            catch (Exception ex)
            {
                NLogUtil.ErrorTxt($"AddBeiKeHost Json Prarse Error:{ex.Message}");
                result = false;
            }
            if (result == false)
            {
                NLogUtil.InfoTxt("【贝壳 IP已用完】");
            }



            return(result);
        }
Пример #3
0
        /// <summary>
        /// 极光 http://d.jghttp.golangapi.com/getip?num=20&type=1&pro=&city=0&yys=0&port=1&pack=20503&ts=0&ys=0&cs=0&lb=1&sb=0&pb=4&mr=1&regions=
        /// </summary>
        public static bool AddJiGuangHost()
        {
            HttpClient httpClient = new HttpClient();
            var        rep        = httpClient.GetAsync(JiGuangUrl);
            var        json       = rep.Result.Content.ReadAsStringAsync();
            var        list       = json.Result.Split("\r\n", StringSplitOptions.RemoveEmptyEntries);
            bool       result     = true;

            try
            {
                if (list.Length == 1)
                {
                    JObject j = JObject.Parse(list[0]);
                    if (Convert.ToBoolean(j["success"]) == false)
                    {
                        result = false;
                    }
                }
            }
            catch
            {
                result = false;
            }
            if (result)
            {
                foreach (var host in list)
                {
                    _proxyHosts.Push(host);
                }
            }
            else
            {
                NLogUtil.InfoTxt("【极光 IP已用完】");
            }

            return(result);
        }
Пример #4
0
        private static void runProxyPlatform()
        {
            while (_stPlantSources.Count > 0)
            {
                var platform = _stPlantSources.Peek();
                NLogUtil.InfoTxt($"切换 {platform} 代理平台");
                bool result = true;

                switch (platform)
                {
                case PlantSource.BeiKe:
                    result = AddBeiKeHost();
                    break;

                case PlantSource.FeiZhu:
                    result = AddFeiZhuHost();
                    break;

                case PlantSource.JiGuang:
                    result = AddJiGuangHost();
                    break;

                case PlantSource.ZhiMa:
                    result = AddZhiMaHost();
                    break;
                }
                if (!result)
                {
                    _stPlantSources.Pop();
                }
                else
                {
                    return;
                }
            }
        }