Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.Linq;
- using System.Text;
- using System.Net;
- using System.IO;
- using System.Data;
- using System.Data.SqlClient;
- using System.Text.RegularExpressions;
- namespace Proxies
- {
- class Program
- {
- static CookieAwareWebClient webClient = new CookieAwareWebClient();
- static void Main(string[] args)
- {
- GetProxiesfromProxyList(10000);
- GetProxiesfromXRoxy(115);
- }
- private static void drawTextProgressBar(int progress, int total)
- {
- //draw empty progress bar
- Console.CursorLeft = 0;
- Console.Write("["); //start
- Console.CursorLeft = 32;
- Console.Write("]"); //end
- Console.CursorLeft = 1;
- float onechunk = 30.0f / total;
- //draw filled part
- int position = 1;
- for (int i = 0; i < onechunk * progress; i++)
- {
- Console.BackgroundColor = ConsoleColor.Gray;
- Console.CursorLeft = position++;
- Console.Write(" ");
- }
- //draw unfilled part
- for (int i = position; i <= 31; i++)
- {
- Console.BackgroundColor = ConsoleColor.Black;
- Console.CursorLeft = position++;
- Console.Write(" ");
- }
- //draw totals
- Console.CursorLeft = 35;
- Console.BackgroundColor = ConsoleColor.Black;
- Console.Write(progress.ToString() + " of " + total.ToString() + " "); //blanks at the end remove any excess
- }
- private static void GetProxiesfromProxyList(int pages)
- {
- ArrayList listArray = new ArrayList();
- for (int inc = 0; inc < pages; inc++)
- {
- try
- {
- string resp = webClient.DownloadString("http://www.proxylist.net/list/0/0/1/0/" + inc.ToString());
- if (resp.Contains("No proxies found!"))
- break;
- MatchCollection listingMatches = Regex.Matches(resp, "<tr title=\"(.+)\"><td><a href=\"/proxy/(.+):(.+)\">(.+):(.+)</a>");
- foreach (Match m in listingMatches)
- {
- string proxy = m.Groups[2].Value + ":" + m.Groups[3].Value;
- listArray.Add(proxy);
- }
- }
- catch
- { }
- }
- int i = 0;
- foreach (string proxy in listArray)
- {
- try
- {
- i++;
- Console.Clear();
- drawTextProgressBar(i, listArray.Count);
- if (proxyBasicTest(proxy))
- {
- SqlConnection Conn = new SqlConnection("Data Source=localhost;Initial Catalog=Scraping;Integrated Security=SSPI;");
- SqlCommand Comm = new SqlCommand("insertProxy", Conn);
- Comm.CommandType = System.Data.CommandType.StoredProcedure;
- Comm.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ip", proxy.Split(':')[0]));
- Comm.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Port", proxy.Split(':')[1]));
- Conn.Open();
- Comm.ExecuteNonQuery();
- Conn.Close();
- Console.WriteLine("\n\nAdded: " + proxy);
- }
- }
- catch
- { }
- }
- }
- private static void GetProxiesfromXRoxy(int pages)
- {
- ArrayList listArray = new ArrayList();
- for (int inc = 0; inc < pages; inc++)
- {
- try
- {
- string resp = webClient.DownloadString("http://www.xroxy.com/proxylist.php?port=&type=&ssl=&country=&latency=&reliability=&sort=reliability&desc=true&pnum=" + inc.ToString());
- drawTextProgressBar(inc, pages);
- MatchCollection listingMatches = Regex.Matches(resp, "&host=(?<host>.*)&port=(?<port>.*)&");
- foreach (Match m in listingMatches)
- {
- string proxy = m.Groups["host"].Value + ":" + m.Groups["port"].Value.Split('&')[0];
- listArray.Add(proxy);
- }
- }
- catch
- { }
- }
- int i = 0;
- foreach (string proxy in listArray)
- {
- try
- {
- i++;
- Console.Clear();
- drawTextProgressBar(i, listArray.Count);
- double ratio = (double)listArray.Count / (double)i;
- Console.WriteLine(" " + Convert.ToInt32((ratio * 100)).ToString() + "%");
- if (proxyBasicTest(proxy))
- {
- SqlConnection Conn = new SqlConnection("Data Source=localhost;Initial Catalog=Scraping;Integrated Security=SSPI;");
- SqlCommand Comm = new SqlCommand("insertProxy", Conn);
- Comm.CommandType = System.Data.CommandType.StoredProcedure;
- Comm.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ip", proxy.Split(':')[0]));
- Comm.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Port", proxy.Split(':')[1]));
- Conn.Open();
- Comm.ExecuteNonQuery();
- Conn.Close();
- }
- }
- catch
- { }
- }
- }
- private static bool proxyBasicTest(string proxy)
- {
- try
- {
- HttpWebRequest wrWebRequest = WebRequest.Create("http://manta.com") as HttpWebRequest;
- WebProxy Proxy = new WebProxy(proxy.Split(':')[0], int.Parse(proxy.Split(':')[1]));
- wrWebRequest.Proxy = Proxy;
- wrWebRequest.Timeout = 5000;
- HttpWebResponse hwrWebResponse = (HttpWebResponse)wrWebRequest.GetResponse();
- System.IO.StreamReader srResponseReader = new System.IO.StreamReader(hwrWebResponse.GetResponseStream());
- string strResponseData = srResponseReader.ReadToEnd();
- srResponseReader.Close();
- if (strResponseData.Contains("codeen"))
- return false;
- if (strResponseData.Contains("manta"))
- return true;
- return false;
- }
- catch (Exception ex)
- {
- return false;
- }
- }
- }
- public class CookieAwareWebClient : WebClient
- {
- public CookieContainer m_container = new CookieContainer();
- protected override WebRequest GetWebRequest(Uri address)
- {
- WebRequest request = base.GetWebRequest(address);
- if (request is HttpWebRequest)
- {
- (request as HttpWebRequest).CookieContainer = m_container;
- (request as HttpWebRequest).Timeout = 5000;
- (request as HttpWebRequest).UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1;";
- (request as HttpWebRequest).KeepAlive = true;
- }
- return request;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment