Visual Basic Proxy Checker

Introduction: This tutorial will be on how to create a proxy checker which will test a list of proxies and report if they respond within 3000ms/3seconds (can be changed using .Timeout). Steps of Creation: Step 1: First we will need to Import two packages, one to use StreamReader and StreamWriter and another to use HttpWebRequest and HttpWebResponse
  1. Imports System.IO
  2. Imports System.Net
Step 2: Add a listbox and three buttons. The listbox will contains the reports of each proxy and the button will be for; Starting the checker, Exporting all the reports and Exporting the working reports First lets make the start script. Let's create an openFileDialog to select a proxy list and check the path isn't nothing/null/empty:
  1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  2. Dim fo As New OpenFileDialog
  3. fo.RestoreDirectory = True
  4. fo.Multiselect = False
  5. fo.Filter = "txt files (*.txt)|*.txt"
  6. fo.FilterIndex = 1
  7. fo.ShowDialog()
  8. If (Not fo.FileName = Nothing) Then
  9. End If
  10. End Sub
Step 3: Now let's create a new "proxies" String List and add all the lines of the file in to the list.
  1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  2. Dim fo As New OpenFileDialog
  3. fo.RestoreDirectory = True
  4. fo.Multiselect = False
  5. fo.Filter = "txt files (*.txt)|*.txt"
  6. fo.FilterIndex = 1
  7. fo.ShowDialog()
  8. If (Not fo.FileName = Nothing) Then
  9. Dim proxies As New List(Of String)
  10. Using sr As New StreamReader(fo.FileName)
  11. While sr.Peek <> -1
  12. proxies.Add(sr.ReadLine())
  13. End While
  14. End Using
  15. End If
  16. End Sub
Step 3: For the last bit of the checking script let's 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 Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  2. Dim fo As New OpenFileDialog
  3. fo.RestoreDirectory = True
  4. fo.Multiselect = False
  5. fo.Filter = "txt files (*.txt)|*.txt"
  6. fo.FilterIndex = 1
  7. fo.ShowDialog()
  8. If (Not fo.FileName = Nothing) Then
  9. Dim proxies As New List(Of String)
  10. Using sr As New StreamReader(fo.FileName)
  11. While sr.Peek <> -1
  12. proxies.Add(sr.ReadLine())
  13. End While
  14. End Using
  15. Dim myProxy As WebProxy
  16. For Each proxy As String In proxies
  17. Try
  18. myProxy = New WebProxy(proxy)
  19. Dim r As HttpWebRequest = HttpWebRequest.Create("http://www.google.com")
  20. r.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.2 Safari/537.36"
  21. r.Timeout = 3000
  22. r.Proxy = myProxy
  23. Dim re As HttpWebResponse = r.GetResponse()
  24. ListBox1.Items.Add("Working Proxy: " & proxy)
  25. Catch ex As Exception
  26. ListBox1.Items.Add("Unresponsive Proxy: " & proxy)
  27. End Try
  28. Next
  29. End If
  30. End Sub
Step 4: Now let's make a quick export all script. A simple script to select a save file, iterate through all the items in the listbox and write the line to the file using StreamWriter:
  1. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  2. If (ListBox1.Items.Count > 0) Then
  3. Dim fs As New SaveFileDialog
  4. fs.RestoreDirectory = True
  5. fs.Filter = "txt files (*.txt)|*.txt"
  6. fs.FilterIndex = 1
  7. fs.ShowDialog()
  8. If Not (fs.FileName = Nothing) Then
  9. Using sw As New StreamWriter(fs.FileName)
  10. For Each line As String In ListBox1.Items
  11. sw.WriteLine(line)
  12. Next
  13. End Using
  14. End If
  15. End If
  16. End Sub
Step 5: Now for the export working proxies script. It's the exact same as the export all script except we want to check if the line starts with "Working Proxy: ". Alternatively we could setup a list and when we check them we could add the working ones to a list and read that.
  1. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  2. If (ListBox1.Items.Count > 0) Then
  3. Dim fs As New SaveFileDialog
  4. fs.RestoreDirectory = True
  5. fs.Filter = "txt files (*.txt)|*.txt"
  6. fs.FilterIndex = 1
  7. fs.ShowDialog()
  8. If Not (fs.FileName = Nothing) Then
  9. Using sw As New StreamWriter(fs.FileName)
  10. For Each line As String In ListBox1.Items
  11. If (line.StartsWith("Working Proxy: ")) Then sw.WriteLine(line)
  12. Next
  13. End Using
  14. End If
  15. End If
  16. End Sub
Project Completed! That's it! Below is the source code and you can download the project from the attached files below.
  1. Imports System.IO
  2. Imports System.Net
  3. Public Class Form1
  4. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  5. Dim fo As New OpenFileDialog
  6. fo.RestoreDirectory = True
  7. fo.Multiselect = False
  8. fo.Filter = "txt files (*.txt)|*.txt"
  9. fo.FilterIndex = 1
  10. fo.ShowDialog()
  11. If (Not fo.FileName = Nothing) Then
  12. Dim proxies As New List(Of String)
  13. Using sr As New StreamReader(fo.FileName)
  14. While sr.Peek <> -1
  15. proxies.Add(sr.ReadLine())
  16. End While
  17. End Using
  18. Dim myProxy As WebProxy
  19. For Each proxy As String In proxies
  20. Try
  21. myProxy = New WebProxy(proxy)
  22. Dim r As HttpWebRequest = HttpWebRequest.Create("http://www.google.com")
  23. r.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.2 Safari/537.36"
  24. r.Timeout = 3000
  25. r.Proxy = myProxy
  26. Dim re As HttpWebResponse = r.GetResponse()
  27. ListBox1.Items.Add("Working Proxy: " & proxy)
  28. Catch ex As Exception
  29. ListBox1.Items.Add("Unresponsive Proxy: " & proxy)
  30. End Try
  31. Next
  32. End If
  33. End Sub
  34.  
  35. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  36. If (ListBox1.Items.Count > 0) Then
  37. Dim fs As New SaveFileDialog
  38. fs.RestoreDirectory = True
  39. fs.Filter = "txt files (*.txt)|*.txt"
  40. fs.FilterIndex = 1
  41. fs.ShowDialog()
  42. If Not (fs.FileName = Nothing) Then
  43. Using sw As New StreamWriter(fs.FileName)
  44. For Each line As String In ListBox1.Items
  45. sw.WriteLine(line)
  46. Next
  47. End Using
  48. End If
  49. End If
  50. End Sub
  51.  
  52. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  53. If (ListBox1.Items.Count > 0) Then
  54. Dim fs As New SaveFileDialog
  55. fs.RestoreDirectory = True
  56. fs.Filter = "txt files (*.txt)|*.txt"
  57. fs.FilterIndex = 1
  58. fs.ShowDialog()
  59. If Not (fs.FileName = Nothing) Then
  60. Using sw As New StreamWriter(fs.FileName)
  61. For Each line As String In ListBox1.Items
  62. If (line.StartsWith("Working Proxy: ")) Then sw.WriteLine(line)
  63. Next
  64. End Using
  65. End If
  66. End If
  67. End Sub
  68. End Class

Comments

Submitted byHassaan (not verified)on Mon, 07/07/2014 - 02:15

Hello Josh, Great Work, Are You Good At Making Patches.... I Would Like You To Join My Blog... If You're Interested, Contact Me At: [email protected]

Add new comment