Esempio n. 1
0
        public void GetYChartsEpsData(List <Company> cList)
        {
            List <Task> tasks = new List <Task>();

            current = 0;
            System.Net.IPAddress[] ips = System.Net.Dns.GetHostEntry("proxy-nl.privateinternetaccess.com").AddressList;

            List <com.LandonKey.SocksWebProxy.SocksWebProxy> proxies = new List <com.LandonKey.SocksWebProxy.SocksWebProxy>(ips.Length);

            foreach (System.Net.IPAddress ip in ips)
            {
                com.LandonKey.SocksWebProxy.Proxy.ProxyConfig pc = new com.LandonKey.SocksWebProxy.Proxy.ProxyConfig(System.Net.IPAddress.Parse("127.0.0.1"), 1080, ip, 1080, com.LandonKey.SocksWebProxy.Proxy.ProxyConfig.SocksVersion.Five, "x7212591", "c4gkjs4rSg");
                var proxy = new com.LandonKey.SocksWebProxy.SocksWebProxy(pc);
                proxies.Add(proxy);
            }

            int proxyCnt = 0;

            for (int i = 0; i < cList.Count; i++)
            {
                Company c = cList[i];
                var     t = new Task(() => ProcessSymbolYChartEps(cList.Count, c, proxies[proxyCnt]));
                tasks.Add(t);

                proxyCnt++;
                if (proxyCnt >= proxies.Count)
                {
                    proxyCnt = 0;
                }
            }
            sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            StartAndWaitAllThrottled(tasks, proxies.Count, 20000000);
        }
Esempio n. 2
0
        public static string Request(string url)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:52.0) Gecko/20100101 Firefox/52.0"; // Setting user agent can help avoid site blocks.
            com.LandonKey.SocksWebProxy.Proxy.ProxyConfig config = new com.LandonKey.SocksWebProxy.Proxy.ProxyConfig(IPAddress.Loopback, 8181, IPAddress.Loopback, 9150, com.LandonKey.SocksWebProxy.Proxy.ProxyConfig.SocksVersion.Five);
            request.Proxy     = new SocksWebProxy(config);
            request.KeepAlive = false;

            try
            {
                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    int resp_code = (int)response.StatusCode;
                    if (resp_code != 502 || resp_code != 301 || resp_code != 404)
                    {
                        using (var reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")))
                        {
                            string content = reader.ReadToEnd();
                            return(content);
                        }
                    }
                    else
                    {
                        return("Failed - Response: " + resp_code.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                return("\n\n" + ex.ToString());
            }
        }