Pertama kita perlu Impor
dua paket, satu untuk menggunakan StreamReader dan StreamWriter dan lain untuk
menggunakan HttpWebRequest dan HttpWebResponse.
1. Imports System.IO
2. Imports System.Net
Tambahkan listbox dan tiga tombol. Listbox akan berisi
laporan masing-masing proxy dan tombol akan untuk; Mulai checker, Mengekspor
semua laporan dan Mengekspor laporan kerja
Pertama mari kita membuat script awal. Mari kita
membuat OpenFileDialog untuk memilih daftar proxy dan memeriksa jalur ini tidak
ada / null / kosong:
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
Sekarang mari kita membuat baru "proxy"
Daftar String dan tambahkan semua baris dari file ke dalam daftar.
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
Untuk bit terakhir dari script memeriksa mari kita
membuat HttpWebRequest ke Google, mengaturproxy ke alamat saat ini dan
menetapkan batas waktu untuk permintaan menerima respon terhadap
3000ms/3seconds. Jika mendapat respon akan terus dan menambahkan proxy sebagai
"Bekerja" untuk kotak daftar, selain itu akan menangkap kesalahan dan
melaporkannya sebagai "tdk".
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
Sekarang mari kita membuat ekspor cepat semua skrip.
Sebuah script sederhana untuk memilih menyimpan file, iterate melalui semua
item dalam listbox dan menulis baris ke file menggunakan 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
Sekarang untuk ekspor bekerja proxy skrip. Ini sama
persis seperti ekspor semua skrip kecualikita ingin memeriksa apakah saluran
dimulai dengan "Proxy Bekerja:". Atau kita bisa setup daftar dan
ketika kami memeriksa mereka kita bisa menambahkan yang bekerja untuk daftar
dan membacanya.
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
Dan Selesai !
Anda Bisa Melihat Semua Skrip di bawah ini
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
Post a Comment