Advertisement
Guest User

BuckleyInDaHouse

a guest
Aug 20th, 2008
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Net;
  5. using System.Collections;
  6. using System.IO;
  7. using System.Windows.Forms;
  8.  
  9. namespace Proxy_Checker
  10. {
  11.     class Program
  12.     {
  13.         private static int ProxyCount = 0;
  14.         private static string[] split;
  15.         private static string Myproxy;
  16.  
  17.         private static int ReturnPort(String Proxy)
  18.         {
  19.             try
  20.             {
  21.                 split = Proxy.Split(':');
  22.             }
  23.             catch (ArgumentException)
  24.             {
  25.                 ProxyCount++;
  26.                
  27.             }
  28.             return int.Parse(split[1]);
  29.         }
  30.         private static int TimeOut;
  31.         public static List<String> MyList = new List<string>();
  32.  
  33.         private static String ReturnAddress(String Proxy)
  34.         {
  35.             try
  36.             {
  37.                 split = Proxy.Split(':');
  38.             }
  39.             catch (ArgumentException)
  40.             {
  41.                 ProxyCount++;
  42.                
  43.             }
  44.             return split[0];
  45.         }
  46.  
  47.         private static void LoadProxies()
  48.         {
  49.             try
  50.             {
  51.                 if (!File.Exists(Application.StartupPath + "/Proxies.txt"))
  52.                 {
  53.                     Console.WriteLine("Proxy text file doesn't exist, please fill it up now");
  54.                     File.Create(Application.StartupPath + "/Proxies.txt");
  55.                     Console.Beep(5000, 2000);
  56.                     System.Threading.Thread.Sleep(5000);
  57.                     Environment.Exit(0);
  58.                 }
  59.                 else if (File.Exists(Application.StartupPath + "/Proxies.txt"))
  60.                 {
  61.                     StreamReader reader = new StreamReader(Application.StartupPath + "/Proxies.txt");
  62.                     while (reader.Peek() > -1)
  63.                     {
  64.                         MyList.Add(reader.ReadLine());
  65.                         //Console.WriteLine(reader.ReadLine());
  66.                     }
  67.                 }
  68.             }
  69.             catch (IOException)
  70.             {
  71.                 Console.WriteLine("Input/Output Exception");
  72.                 Console.Beep(5000, 2000);
  73.                 System.Threading.Thread.Sleep(5000);
  74.                 Environment.Exit(0);
  75.             }
  76.         }
  77.  
  78.         private static void SaveProxy(String Proxy)
  79.         {
  80.             try
  81.             {
  82.                 if (!File.Exists(Application.StartupPath + "/Working Proxies.txt"))
  83.                 {
  84.                     StreamReader reader = new StreamReader(Application.StartupPath + "/Working Proxies.txt");
  85.                     StreamWriter writer = new StreamWriter(Application.StartupPath + "/Working Proxies.txt");
  86.                     File.Create(Application.StartupPath + "/Working Proxies.txt");
  87.                     writer.WriteLine(Proxy);
  88.                     writer.Close();
  89.                 }
  90.                 else
  91.                 {
  92.                     StreamReader reader = new StreamReader(Application.StartupPath + "/Working Proxies.txt");
  93.                     StreamWriter writer = new StreamWriter(Application.StartupPath + "/Working Proxies.txt");
  94.                     File.Create(Application.StartupPath + "/Working Proxies.txt");
  95.                     string tempp = reader.ReadToEnd();
  96.                     writer.Write(tempp + Environment.NewLine + Proxy);
  97.                     writer.Close();
  98.                 }
  99.             }
  100.             catch (IOException)
  101.             {
  102.                 Console.WriteLine("Error saving proxy");
  103.             }
  104.         }
  105.  
  106.         static void Main(string[] args)
  107.         {
  108.             Console.WriteLine("Proxy Checker ~ BuckleyInDaHouse");
  109.             Console.WriteLine("");
  110.         R:
  111.             Console.WriteLine("Please enter a timeout in seconds");
  112.             try
  113.             {
  114.                 TimeOut = Convert.ToInt32(Console.ReadLine()) * 1000;
  115.             }
  116.             catch (ArgumentException)
  117.             {
  118.                 Console.WriteLine("Error reading your timeout number");
  119.                 Console.WriteLine(Environment.NewLine);
  120.                 goto R;
  121.             }
  122.             LoadProxies();
  123.             while (ProxyCount <= MyList.Count)
  124.             {
  125.                 Console.Title = "BuckleyInDaHouse Proxy Checker ~~ On proxy " + ProxyCount + " of a total " + MyList.Count;
  126.                 try
  127.                 {
  128.                     System.Diagnostics.Stopwatch Watch = new System.Diagnostics.Stopwatch();
  129.                     Watch.Start();
  130.                     Myproxy = MyList[ProxyCount];
  131.                      WebProxy pr = new WebProxy(ReturnAddress(Myproxy), ReturnPort(Myproxy));
  132.                      //Console.WriteLine("Address: " + ReturnAddress(Myproxy) + " Port: " + ReturnPort(Myproxy));
  133.                     WebRequest request = HttpWebRequest.Create("http://big.joshua.buckley.googlepages.com/ProxyTester.txt");
  134.                     request.Proxy = pr;
  135.                     request.Timeout = TimeOut;
  136.                     WebResponse response = request.GetResponse();
  137.                     StreamReader myreader = new StreamReader(response.GetResponseStream());
  138.                     string temp = myreader.ReadToEnd();
  139.                     if (temp.IndexOf("Hello World") > 0)
  140.                     {
  141.                         Watch.Stop();
  142.                         int TempTimeOut = Watch.Elapsed.Milliseconds;
  143.                         Console.WriteLine("Proxy: " + Myproxy + " Works.  TimeOut: " + TempTimeOut);
  144.                         SaveProxy(Myproxy);
  145.                         ProxyCount++;
  146.                     }
  147.                     else if (string.IsNullOrEmpty(temp))
  148.                     {
  149.                         Console.WriteLine("Proxy: " + Myproxy + " doesn't Work.");
  150.                         ProxyCount++;
  151.                     }
  152.                 }
  153.                 catch (WebException web)
  154.                 {
  155.                     Console.WriteLine("Proxy: " + Myproxy + " Timed out");
  156.                     ProxyCount++;
  157.                 }
  158.             }
  159.         }
  160.     }
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement