Proxy Checker using C#

In this tutorial, we will create a proxy checker program which will test a list of proxies and report if they respond within a faster time. Now, let's start this tutorial! 1. Let's start with creating a Windows Form Application in C# for this tutorial by following the following steps in Microsoft Visual Studio 2010: Go to File, click New Project, and choose Windows Application. 2. Next, add three buttons for starting the checker, exporting all the reports and exporting the working reports; add also a ListBox that will contain the reports of each proxy. 3. Import these two namespaces.
  1. using System.IO;
  2. using System.Net;
4. For Button1, put this code below to select a proxy list and check the path isn't nothing/null/empty.
  1. private void Button1_Click(object sender, EventArgs e)
  2. {
  3. OpenFileDialog fo = new OpenFileDialog();
  4. fo.RestoreDirectory = true;
  5. fo.Multiselect = false;
  6. fo.Filter = "txt files (*.txt)|*.txt";
  7. fo.FilterIndex = 1;
  8. fo.ShowDialog();
  9. if (fo.FileName != null)
  10. {
  11. }
  12. }
Then let's create a new proxies in the String List and add all the lines of the file in to the list in Button1.
  1. private void Button1_Click(object sender, EventArgs e)
  2. {
  3. OpenFileDialog fo = new OpenFileDialog();
  4. fo.RestoreDirectory = true;
  5. fo.Multiselect = false;
  6. fo.Filter = "txt files (*.txt)|*.txt";
  7. fo.FilterIndex = 1;
  8. fo.ShowDialog();
  9. if (fo.FileName != null)
  10. {
  11. List<string> proxies = new List<string>();
  12. using (StreamReader sr = new StreamReader(fo.FileName))
  13. {
  14. while (sr.Peek != -1)
  15. {
  16. proxies.Add(sr.ReadLine());
  17. }
  18. }
  19.  
  20. }
  21. }
Now for the checking of script we will create a HTTPWebRequest to Google, set the proxy to the current address and set a timeout for the request of receiving the response to 3000ms/3seconds. If it gets a response it will continue and add the proxy as Working to the list box, otherwise it will catch the error and report it as Unresponsive.
  1. private void Button1_Click(object sender, EventArgs e)
  2. {
  3. OpenFileDialog fo = new OpenFileDialog();
  4. fo.RestoreDirectory = true;
  5. fo.Multiselect = false;
  6. fo.Filter = "txt files (*.txt)|*.txt";
  7. fo.FilterIndex = 1;
  8. fo.ShowDialog();
  9. if (fo.FileName != null)
  10. {
  11. List<string> proxies = new List<string>();
  12. using (StreamReader sr = new StreamReader(fo.FileName))
  13. {
  14. while (sr.Peek != -1)
  15. {
  16. proxies.Add(sr.ReadLine());
  17. }
  18. }
  19.  
  20. WebProxy myProxy = default(WebProxy);
  21. foreach (string proxy in proxies)
  22. {
  23. try
  24. {
  25. myProxy = new WebProxy(proxy);
  26. HttpWebRequest r = HttpWebRequest.Create("http://www.google.com");
  27. r.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.2 Safari/537.36";
  28. r.Timeout = 3000;
  29. r.Proxy = myProxy;
  30. HttpWebResponse re = r.GetResponse();
  31. ListBox1.Items.Add("Working Proxy: " + proxy);
  32. }
  33. catch (Exception)
  34. {
  35. ListBox1.Items.Add("Unresponsive Proxy: " + proxy);
  36. }
  37. }
  38. }
  39. }
5. For Button2, put this code below to make a quick export all script.
  1. private void Button2_Click(object sender, EventArgs e)
  2. {
  3. if (ListBox1.Items.Count > 0)
  4. {
  5. SaveFileDialog fs = new SaveFileDialog();
  6. fs.RestoreDirectory = true;
  7. fs.Filter = "txt files (*.txt)|*.txt";
  8. fs.FilterIndex = 1;
  9. fs.ShowDialog();
  10. if (!(fs.FileName == null))
  11. {
  12. using (StreamWriter sw = new StreamWriter(fs.FileName))
  13. {
  14. foreach (string line in ListBox1.Items)
  15. {
  16. sw.WriteLine(line);
  17. }
  18. }
  19.  
  20. }
  21. }
  22. }
6. Lastly for Button3, put this code below to export working proxies script.
  1. private void Button3_Click(object sender, EventArgs e)
  2. {
  3. if (ListBox1.Items.Count > 0)
  4. {
  5. SaveFileDialog fs = new SaveFileDialog();
  6. fs.RestoreDirectory = true;
  7. fs.Filter = "txt files (*.txt)|*.txt";
  8. fs.FilterIndex = 1;
  9. fs.ShowDialog();
  10. if (!(fs.FileName == null))
  11. {
  12. using (StreamWriter sw = new StreamWriter(fs.FileName))
  13. {
  14. foreach (string line in ListBox1.Items)
  15. {
  16. if (line.StartsWith("Working Proxy: "))
  17. {
  18. sw.WriteLine(line);
  19. }
  20. }
  21. }
  22.  
  23. }
  24. }
  25. }
Full source code:
  1. using System.IO;
  2. using System.Net;
  3.  
  4.  
  5.  
  6. public class Form1
  7. {
  8. private void Button1_Click(object sender, EventArgs e)
  9. {
  10. OpenFileDialog fo = new OpenFileDialog();
  11. fo.RestoreDirectory = true;
  12. fo.Multiselect = false;
  13. fo.Filter = "txt files (*.txt)|*.txt";
  14. fo.FilterIndex = 1;
  15. fo.ShowDialog();
  16. if (fo.FileName != null)
  17. {
  18. List<string> proxies = new List<string>();
  19. using (StreamReader sr = new StreamReader(fo.FileName))
  20. {
  21. while (sr.Peek() != -1)
  22. {
  23. proxies.Add(sr.ReadLine());
  24. }
  25. }
  26.  
  27. WebProxy myProxy = default(WebProxy);
  28. foreach (string proxy in proxies)
  29. {
  30. try
  31. {
  32. myProxy = new WebProxy(proxy);
  33. HttpWebRequest r = HttpWebRequest.Create("http://www.google.com");
  34. r.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.2 Safari/537.36";
  35. r.Timeout = 3000;
  36. r.Proxy = myProxy;
  37. HttpWebResponse re = r.GetResponse();
  38. ListBox1.Items.Add("Working Proxy: " + proxy);
  39. }
  40. catch (Exception)
  41. {
  42. ListBox1.Items.Add("Unresponsive Proxy: " + proxy);
  43. }
  44. }
  45. }
  46. }
  47.  
  48. private void Button2_Click(object sender, EventArgs e)
  49. {
  50. if (ListBox1.Items.Count > 0)
  51. {
  52. SaveFileDialog fs = new SaveFileDialog();
  53. fs.RestoreDirectory = true;
  54. fs.Filter = "txt files (*.txt)|*.txt";
  55. fs.FilterIndex = 1;
  56. fs.ShowDialog();
  57. if (!(fs.FileName == null))
  58. {
  59. using (StreamWriter sw = new StreamWriter(fs.FileName))
  60. {
  61. foreach (string line in ListBox1.Items)
  62. {
  63. sw.WriteLine(line);
  64. }
  65. }
  66.  
  67. }
  68. }
  69. }
  70.  
  71. private void Button3_Click(object sender, EventArgs e)
  72. {
  73. if (ListBox1.Items.Count > 0)
  74. {
  75. SaveFileDialog fs = new SaveFileDialog();
  76. fs.RestoreDirectory = true;
  77. fs.Filter = "txt files (*.txt)|*.txt";
  78. fs.FilterIndex = 1;
  79. fs.ShowDialog();
  80. if (!(fs.FileName == null))
  81. {
  82. using (StreamWriter sw = new StreamWriter(fs.FileName))
  83. {
  84. foreach (string line in ListBox1.Items)
  85. {
  86. if (line.StartsWith("Working Proxy: "))
  87. {
  88. sw.WriteLine(line);
  89. }
  90. }
  91. }
  92.  
  93. }
  94. }
  95. }
  96. }
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards, Engr. Lyndon Bermoy IT Instructor/System Developer/Android Developer/Freelance Programmer If you have some queries, feel free to contact the number or e-mail below. Mobile: 09488225971 Landline: 826-9296 E-mail:[email protected] Add and Follow me on Facebook: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

Comments

Submitted byValera (not verified)on Tue, 08/23/2022 - 23:25

Now work

Add new comment