Esempio n. 1
0
        public static string[] LoadHideMyAss(string proxyURL)
        {
            HttpClient loader = new HttpClient();
            List<HideMyAssProxyStruct> proxies = new List<HideMyAssProxyStruct>();
            string baseURL = "http://hidemyass.com";
            string portImg = "/proxy-list/img/port";

            string localData;
            string proxyInfo;

            string response = "";

            try
            {
                response = loader.DownloadString(proxyURL);
            }
            catch (Exception e)
            {
                ConsoleLog.WriteLine("LoadHideMyAss: load 1 error. " + e.Message);
            }

            int page = 1;
            ConsoleLog.WriteLine(response, "ProxyLog1.txt");

            while (response.Contains(portImg))
            {
                ConsoleLog.WriteLine(proxyURL + '/' + page.ToString());

                localData = CommonUtils.GetStringBetween(response, "Anonymity</td>", "pagination");
                ConsoleLog.WriteLine(localData, "ProxyLog2.txt");

                while (localData.Contains("<tr class=\"row"))
                {
                    localData = localData.Substring(localData.IndexOf("<tr class=\"row") + 10);

                    //proxyInfo = CommonUtils.GetStringBetween(localData, "<!--", "style=\"margin");
                    proxyInfo = CommonUtils.GetStringBetween(localData, "<!--", "</tr>");
                    ConsoleLog.WriteLine(proxyInfo, "ProxyLog3.txt");
                    if (proxyInfo.Contains("planetlab"))
                    {
                        string proxyIP = CommonUtils.GetStringBetween(proxyInfo, "gif\">", "</td>");
                        ConsoleLog.WriteLine(proxyIP + " - PlanetLab");
                        continue;
                    }

                    HideMyAssProxyStruct proxy = new HideMyAssProxyStruct();

                    proxy.IP = CommonUtils.GetStringBetween(proxyInfo, "<td>", "</td>");

                    if (proxyInfo.Contains("None"))
                    {
                        ConsoleLog.WriteLine(proxy.IP + " - not anonymous");
                        continue;
                    }

                    proxy.PortImgURL = baseURL + CommonUtils.GetStringBetween(proxyInfo, "<img src=\"", "\"");

                    proxies.Add(proxy);
                }

                page++;
                //if (page > 3) break; // Debug
                try
                {
                    response = loader.DownloadString(proxyURL + '/' + page.ToString());
                    ConsoleLog.WriteLine(response, "ProxyLog1.txt");
                }
                catch (Exception e)
                {
                    ConsoleLog.WriteLine("LoadHideMyAss: load 2 error. " + e.Message);
                }
            }

            LoadHideMyAssCaptchaPreloader();

            const int poolSize = 10;
            System.Threading.Thread[] pool = new System.Threading.Thread[poolSize];
            int count = proxies.Count;
            int i;

            i = 0;
            while (i < count)
            {
                int freeThread = -1;

                for (int ft = 0; ft < poolSize; ft++)
                {
                    if ((pool[ft] == null) || (!pool[ft].IsAlive))
                    {
                        freeThread = ft;
                        break;
                    }
                }

                if (freeThread == -1)
                {
                    System.Threading.Thread.Sleep(100);
                    continue;
                }

                ConsoleLog.WriteLine(
                    "Processing proxy " + (i + 1).ToString() + "/" + count.ToString() +
                    ", thread " + (freeThread+1).ToString());
                pool[freeThread] = new System.Threading.Thread(LoadHideMyAssCaptcha);
                pool[freeThread].Start(proxies[i]);

                i++;
            }

            i = 0;
            while (i < poolSize)
            {
                if ((pool[i % poolSize] != null) && (pool[i % poolSize].IsAlive))
                {
                    System.Threading.Thread.Sleep(200);
                    continue;
                }

                i++;
            }

            List<string> result = new List<string>();
            foreach (HideMyAssProxyStruct proxy in proxies)
            {
                if (!String.IsNullOrEmpty(proxy.Port))
                    result.Add(proxy.FullProxy);
            }

            if (result.Count > 0)
            {
                var streamWriter = new StreamWriter(
                    storePath + "\\proxy.txt",
                    false);
                foreach (string proxy in result)
                {
                    streamWriter.WriteLine(proxy);
                }
                streamWriter.Close();
            }

            return result.ToArray();
        }
Esempio n. 2
0
        // update Port in proxy class
        private static void LoadHideMyAssCaptcha(HideMyAssProxyStruct proxy)
        {
            HttpClient connection = new HttpClient();

            string num = "";
            byte[] bitmapData = null;

            try
            {
                bitmapData = connection.DownloadData(proxy.PortImgURL);
            }
            catch (Exception e)
            {
                ConsoleLog.WriteLine("LoadHideMyAss: load 3 error. " + e.Message);
                return;
            }

            //Bitmap source = new Bitmap(new MemoryStream(bitmapData));
            //source.Save(@"C:\source" + count.ToString() + ".bmp");
            Bitmap captcha = LoadHideMyAssCaptchaCutSource(new Bitmap(new MemoryStream(bitmapData)), 0);
            //Bitmap captcha = CaptchaCutSource(new Bitmap(@"C:\source.bmp"));
            //captcha.Save(@"C:\cut" + count.ToString() + ".bmp");

            for (int captchaX = 0; captchaX < captcha.Width - hidemyassSamplesMaxWidth; captchaX++)
            {
                foreach (Bitmap trySample in hidemyassSamples)
                {
                    Bitmap lSample;
                    lock (locker)
                    {
                        lSample = new Bitmap(trySample);
                    }

                    if (LoadHideMyAssCaptchaCompareSamples(captcha, captchaX, lSample))
                    {
                        num += hidemyassSamples.IndexOf(trySample).ToString();
                        break;
                    }
                }
            }

            proxy.Port = num.ToString();

            return;
        }