Overview.
Welcome to yet another of my fine tutorials!
This is a good method for downloading any lists you might find on the internet, and add each line into an variable. Useful for datamining, email-adress leeching, proxy-leeching and anything else you might want to leech.
The method will treat any document as a textfile, so you will only be able to use it on things like txt, dat, html, xml, cab, ini, db and so on and forth.
The way we read the data into the the variable can be applied on any file, especially useful in information-stealers (not copying, moving or modifying the file but READING it is way more undetectable than any other method). I mean, reading the data into a variable makes it impossible for the computer to associate it with the original file, and therefore any protection the original file might have.
Example file.
Our example file is the proxylist from Tubeincreaser located here.
The code.
A thing called "imports" are required. An import is a specific part of the .net library which we need to Include at the top of our code to load it. So in the very top of the code, before everything else, write:
Code:
Imports System.IO
Imports System.Net.WebRequestMethods
Imports System.Text.RegularExpressions
Not all might be required, but including these 3 makes compitability with older versions of the .net framework more likely.
Next, place a button on your form and in its button_click event, write:
Code:
If System.IO.File.Exists("C:\proxylist.txt") = True Then
System.IO.File.Delete("C:\proxylist.txt")
End If
This will check for the file which we are about to create. Because it is a proxylist we want it to refresh on each download, and most textfiles are no larger than 750KB which makes this no problem.
Continuing on the button click, just below the code we just made, we are going to use a "Try" expression. You should always use this expression when dealing with more complex file operations since it is less likely to glitch out. And if it does you will (most of the time) don't get any memory leaks:
Code:
Try
My.Computer.Network.DownloadFile _
("http://www.tubeincreaser.com/proxylist.txt", _
"C:\proxylist.txt")
This saves the file from the http-address to your C:\ disc. You can name the saved file in anyway you want, does not have to be proxylist.txt.
(If you explore Network.DownloadFile you will find that it works with FTP:// connections, and even have networkcredentials settings!)
The next step of our Try expression will be:
Code:
Dim ioFile As New StreamReader("C:\proxylist.txt")
Dim ioLine As String
Dim ioLines As String
ioFile = the variable that holds all data it can read from the file.
ioLine = holds the individual line which is to be formatted.
ioLines = holds all the text we loaded, and formatted.
What we now are going to do is loading the file in raw data, formatting the raw data into a format with 1 ip & port on each line. Then we save the formatted data into a variable which we are going to use in the end!
Code:
ioLine = ioFile.ReadLine
ioLines = ioLine
While Not ioLine = ""
ioLine = ioFile.ReadLine
ioLines = ioLines & vbCrLf & ioLine
End While
While creates a loop until a certain condition is met, here the condition states that as long as the line read does NOT contain "" (AKA nothing), continue reading the lines.
Look at this code and try understanding what parts of it refers to what parts of the paragraph above the code. If you do not understand what it does, go back and read it again!
Let us examine the string that changes the read text:
Code:
ioLines = ioLines & vbCrLf & ioLine
ioLines, the formatted data is adding itself before any other variables. If we would write ioLines = vbCrLf & ioLine the variable would be rewritten each time. By assigning its own value first, the other variables gets added onto that value. vbCrLf is VB's way of pressing enter when writing. So it first adds the old value. Then it changes the line. Then it adds the new value on the new line. Capich?
And now we finish the Try expression with the Catch and End Try. Catch is, simplified, "if something unexpected happens".
Code:
Catch
MsgBox("Failed to load proxylist. Are you connected to the internet?" & vbCrLf & "Also check if your firewall blocks this program.")
End Try
As you can see we give the user an informative error report. Not like the usual MS errors saying "There was a fault at memory adress 0cX74363". But advice on how the user might fix the error that occured. ALWAYS DO THIS, DAMNIT.(Or I will come after you
)
And we are done! But how do we use it?
Add a richtextbox onto your form. name it RichTextBox_proxies.
Code:
RichTextBox_proxies.Text = ""
RichTextBox_proxies.Text = ioLines
And you will see that each time you click the button, the proxylist will be downloaded, saved to your computer, the RichTextbox cleared and the proxies loaded into the RichTextBox.
There is an error in the part where the text is loaded into the textbox. But I'm not sayin'. And the VB editor won't say it either. But it is there!
There is also some unnecessary parts, regarding obtaining the proxylist... we could skip some saving and go right to the using.
You figure these out yourself, and you have learned way more than just copy/pasting code!
:wave: