C#
VB.NET
I did not use a converter, I wrote it in C# first however, then just used my knowledge of VB.NET to translate it.
Code
using System.IO;Code
string system = Environment.GetFolderPath(Environment.SpecialFolder.System);
//^ Above creates the string system, and stores the system folder path in it
string hosts = system + "\\" + "drivers" + "\\" + "etc" + "\\" + "hosts";
//^ In VB.NET you would only need one slash, but in C# you need two
// ^ basically this takes the string system and adds the path to it
StreamWriter writer = new StreamWriter(hosts);
// ^ Creates a new StreamWriter with the path of our hosts string
writer.Write("##Hosts file edit");
//^ Writes ##Hosts file edit in our hosts file
writer.Write(Environment.NewLine);
//^ Creates a new line, important so text is not all in 1 line
writer.Write("127.0.0.1 www.google.ca");
//^ Writes 127.0.0.1 www.google.ca in our hosts file, redirecting anybody who
//^ goes to google to 127.0.0.1 which is localhost
writer.Write(Environment.NewLine);
//^ See above
writer.Write("127.0.0.1 google.ca");
//^ This is important, because the user cannot go to www.google.ca, but he will
//^ be able to go to google.ca!!
writer.Write(Environment.NewLine);
//^ See above
writer.Write("127.0.0.1 209.85.135.99");
//^ Okay, 209.85.135.99 is the IP address of google.
//^ if you redirect google.ca and www.google.ca then the user will still
//^ be able to go to 209.85.135.99, which is google so we want to block that
//^ Now, if the user tries to go to www.google.ca he will be redirected to
//^ localhost, if he goes to google.ca he will be redirected to localhost
//^ and finally, if he is smart and pings google then he will
//^ get the address 209.85.135.99, but when he tries to go to that he will be
//^ redirected to localhost bwahahahahah
writer.Dispose();
//^ This is important, it closes our streamwriter and saves the data, please
//^ remember writer.Write will clear everything in the hosts file if the style
//^ is not append, but I will not get into that now.
//^ if we did not have our newline this is what our hosts file would look like
//^ ##Hosts file edit127.0.0.1 www.google.ca127.0.0.1 google.ca127.0.0.1 209.85.135.99
//^ but our hosts file has to look like the following in order to be read
//^ ##Hosts file edit
//^ 127.0.0.1 www.google.ca
//^ 127.0.0.1 google.ca
//^ 127.0.0.1 209.85.135.99
//^ I hope you enjoyed my tutorial, feel free to ask for more in C# or VB.NET!VB.NET
Code
Imports System.IOCode
Dim systempath As String = Environment.GetFolderPath(Environment.SpecialFolder.System)
'this creates a new string with the value of the persons system32/62 folder
Dim hosts As String = systempath & "\" & "drivers" & "\" & "etc" & "\\" & "hosts"
'this creates a new string with the value of systempath and the above text
'in VB.NET we do not need two \\'s only one.
Dim writer As New StreamWriter(hosts)
'this creates the streamwriter "writer" and sets its path to our string hosts, done above.
writer.Write("##Hosts file edit")
'writes ##Hosts file edit in our hosts file
'same as in C#
writer.Write(Environment.NewLine)
' Creates a new line, important so text is not all in 1 line
' same as in C#
writer.Write("127.0.0.1 www.google.ca")
' Writes 127.0.0.1 www.google.ca in our hosts file, redirecting anybody who
' goes to google to 127.0.0.1 which is localhost
writer.Write(Environment.NewLine)
' See above
writer.Write("127.0.0.1 google.ca")
' This is important, because the user cannot go to www.google.ca, but he will
' be able to go to google.ca!!
writer.Write(Environment.NewLine)
' See above
writer.Write("127.0.0.1 209.85.135.99")
' Okay, 209.85.135.99 is the IP address of google.
' if you redirect google.ca and www.google.ca then the user will still
' be able to go to 209.85.135.99, which is google so we want to block that
' Now, if the user tries to go to www.google.ca he will be redirected to
' localhost, if he goes to google.ca he will be redirected to localhost
' and finally, if he is smart and pings google then he will
' get the address 209.85.135.99, but when he tries to go to that he will be
' redirected to localhost bwahahahahah
'SAME AS IN C#
writer.Dispose()
' This is important, it closes our streamwriter and saves the data, please
' remember writer.Write will clear everything in the hosts file if the style
' is not append, but I will not get into that now.
' if we did not have our newline this is what our hosts file would look like
' ##Hosts file edit127.0.0.1 www.google.ca127.0.0.1 google.ca127.0.0.1 209.85.135.99
' but our hosts file has to look like the following in order to be read
' ##Hosts file edit
' 127.0.0.1 www.google.ca
' 127.0.0.1 google.ca
' 127.0.0.1 209.85.135.99
' I hope you enjoyed my tutorial, feel free to ask for more in C# or VB.NET!
'SAME AS IN C#I did not use a converter, I wrote it in C# first however, then just used my knowledge of VB.NET to translate it.


