daily pastebin goal
63%
SHARE
TWEET

Form1.vb

a guest Dec 5th, 2011 38 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.Text.RegularExpressions
  2.  
  3. Public Class Form1
  4.     Dim Thread1 As System.Threading.Thread
  5.  
  6.     Private Sub GrabProxies()
  7.  
  8.         CheckForIllegalCrossThreadCalls = False
  9.         Dim i As Integer = 1
  10.  
  11.         Do Until i = NumericUpDown1.Value + 1
  12.             Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://hidemyass.com/proxy-list/" + i.ToString)
  13.             Dim response As System.Net.HttpWebResponse = request.GetResponse
  14.  
  15.             Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())
  16.  
  17.             Dim rssourcecode As String = sr.ReadToEnd
  18.  
  19.             Dim r As New System.Text.RegularExpressions.Regex("(\d{1,4}\.\d{1,4}\.\d{1,4}\.\d{1,4})</span></td>\D+(\d{1,5})</td>\D+<img src=""\S+""\D+""flag"" /> (\w+)\D+\S+\D+(\d+%)\D+\S+\D+(\d+%)""\D+<td>(\w+)\D+"">(\w+)")
  20.             Dim matches As MatchCollection = r.Matches(rssourcecode)
  21.  
  22.             For Each itemcode As Match In matches
  23.  
  24.                 With ListView1.Items.Add("")
  25.                     .SubItems.Add(itemcode.Groups(1).Value)
  26.                     .SubItems.Add(itemcode.Groups(2).Value)
  27.                     .SubItems.Add(itemcode.Groups(3).Value)
  28.                     .SubItems.Add(itemcode.Groups(4).Value)
  29.                     .SubItems.Add(itemcode.Groups(5).Value)
  30.                     .SubItems.Add(itemcode.Groups(6).Value)
  31.                     .SubItems.Add(itemcode.Groups(7).Value)
  32.                 End With
  33.  
  34.             Next
  35.             i = i + 1
  36.         Loop
  37.     End Sub
  38.     Private Sub ListView1_ColumnClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles ListView1.ColumnClick
  39.         '// check if it contains items.
  40.         If Not ListView1.Items.Count = 0 Then lvColumnSort(e.Column, ListView1) '// send Column Index and the ListView used.
  41.     End Sub
  42. #Region "================= SORT LISTVIEW COLUMNS BY SELECTED COLUMN ================="
  43.  
  44.     Private arlSortLvItems As New ArrayList '// adds ListView items to.
  45.     Private bSortDescending As Boolean = True '// Toggles if .Ascending or Descending.
  46.     Private Sub lvColumnSort(ByVal columnIndex As Integer, ByVal selectedListView As ListView)
  47.         With selectedListView
  48.             arlSortLvItems.Clear() '// clear ArrayList for new input.
  49.             For Each itm As ListViewItem In .Items '// loop thru ListView.Items
  50.                 Select Case columnIndex '// check which column is clicked and add items to ArrayList as needed, first item will be the .Sorting item.
  51.                     Case 0 '// IpAdress, Port, Country, Speed.
  52.                         arlSortLvItems.Add(itm.Text & "~" & itm.SubItems(1).Text & "~" & itm.SubItems(2).Text & "~" & itm.SubItems(3).Text & "~" & itm.SubItems(4).Text)
  53.                     Case 1 '// Port, IpAdress, Country, Speed.
  54.                         arlSortLvItems.Add(itm.SubItems(1).Text & "~" & itm.Text & "~" & itm.SubItems(2).Text & "~" & itm.SubItems(3).Text & "~" & itm.SubItems(4).Text)
  55.                     Case 2 '// Country, Speed, IpAdress, Port.
  56.                         arlSortLvItems.Add(itm.SubItems(2).Text & "~" & itm.SubItems(4).Text & "~" & itm.SubItems(3).Text & "~" & itm.Text & "~" & itm.SubItems(1).Text)
  57.                     Case 3 '// Speed, Country, IpAdress, Port.
  58.                         arlSortLvItems.Add(itm.SubItems(4).Text & "~" & itm.SubItems(3).Text & "~" & itm.SubItems(2).Text & "~" & itm.Text & "~" & itm.SubItems(1).Text)
  59.                 End Select
  60.             Next
  61.             arlSortLvItems.Sort() '// sort ArrayList.
  62.             .Items.Clear() '// clear ListView to add Sorted items back.
  63.             getSortOrderOfItems(columnIndex, selectedListView, bSortDescending) '// determines if needed to add .Ascending or .Descending.
  64.             bSortDescending = Not bSortDescending '// Toggle True/False for next click.
  65.         End With
  66.     End Sub
  67.     Private Sub getSortOrderOfItems(ByVal columnIndex As Integer, ByVal selectedListView As ListView, ByVal isDescending As Boolean)
  68.         With selectedListView
  69.             .Sorting = SortOrder.None '// No Sort order.
  70.             If isDescending Then
  71.                 For Each itm As String In arlSortLvItems '// loop thru items in ArrayList.
  72.                     setItemsBackToListView(columnIndex, selectedListView, itm.Split("~"c)) '// .Split to get values as arrays.
  73.                 Next
  74.             Else
  75.                 For i As Integer = arlSortLvItems.Count - 1 To 0 Step -1 '// loop backwards thru items ArrayList.
  76.                     setItemsBackToListView(columnIndex, selectedListView, arlSortLvItems(i).ToString.Split("~"c)) '// .Split to get values as arrays.
  77.                 Next
  78.             End If
  79.         End With
  80.     End Sub
  81.  
  82.     Private Sub setItemsBackToListView(ByVal columnIndex As Integer, ByVal selectedListView As ListView, ByVal ArrayListItem() As String)
  83.         With selectedListView
  84.             Dim lvItem As New ListViewItem '// new ListView Item.
  85.             With lvItem
  86.                 Select Case columnIndex
  87.                     Case 0 '// IpAdress, Port, Country, Speed.
  88.                         .Text = ArrayListItem(0) '// IpAdress.
  89.                         .SubItems.Add(ArrayListItem(1)) '// Port.
  90.                         .SubItems.Add(ArrayListItem(2)) '// Country.
  91.                         .SubItems.Add(ArrayListItem(3)) '// Speed.
  92.                     Case 1 '// Port, IpAdress, Country, Speed.
  93.                         .Text = ArrayListItem(1) '// IpAdress.
  94.                         .SubItems.Add(ArrayListItem(0)) '// Port.
  95.                         .SubItems.Add(ArrayListItem(2)) '// Country.
  96.                         .SubItems.Add(ArrayListItem(3)) '// Speed.
  97.                     Case 2 '// Country, Speed, IpAdress, Port.
  98.                         .Text = ArrayListItem(2) '// IpAdress.
  99.                         .SubItems.Add(ArrayListItem(3)) '// Port.
  100.                         .SubItems.Add(ArrayListItem(0)) '// Country.
  101.                         .SubItems.Add(ArrayListItem(1)) '// Speed.
  102.                     Case 3 '// Speed, Country, IpAdress, Port.
  103.                         .Text = ArrayListItem(2) '// IpAdress.
  104.                         .SubItems.Add(ArrayListItem(3)) '// Port.
  105.                         .SubItems.Add(ArrayListItem(1)) '// Country.
  106.                         .SubItems.Add(ArrayListItem(0)) '// Speed.
  107.                 End Select
  108.             End With
  109.             .Items.Add(lvItem) '// add item back to ListView.
  110.         End With
  111.     End Sub
  112. #End Region
  113.  
  114.     Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk
  115.         Dim myFile As String = SaveFileDialog1.FileName
  116.         Dim myWriter As New IO.StreamWriter(myFile)
  117.         For Each myItem As ListViewItem In ListView1.Items
  118.             If CheckBox1.Checked = True Then
  119.                 myWriter.WriteLine(myItem.Text & myItem.SubItems(1).Text & ":" & myItem.SubItems(2).Text)
  120.             Else
  121.                 myWriter.WriteLine(myItem.Text & myItem.SubItems(1).Text & " | " & myItem.SubItems(2).Text & " | " & myItem.SubItems(3).Text & " | " & myItem.SubItems(4).Text & " | " & myItem.SubItems(5).Text & " | " & myItem.SubItems(6).Text & " | " & myItem.SubItems(7).Text)
  122.             End If
  123.         Next
  124.         myWriter.Close()
  125.     End Sub
  126.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  127.         Thread1 = New System.Threading.Thread(AddressOf GrabProxies)
  128.         Thread1.Start()
  129.     End Sub
  130.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  131.         SaveFileDialog1.ShowDialog()
  132.     End Sub
  133.  
  134.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  135.         ListView1.Items.Clear()
  136.     End Sub
  137. End Class
  138.  
  139.  
RAW Paste Data
Top