A lot of this information is a compilation of what I have asked for or read about on this website. It also comes from my boredom at work when I am messing around with the computers. I will link the Instructables that have helped me accomplish the creation of this file.
The basic idea of editing the file comes from How to "hack this site".
Help with coding came from Neodudeman.
I am not liable for any trouble you cause with this. Use it however you want to mess with computers, but if something goes wrong...well, I warned you.
Step 1: Batch Basics
@echo off - this will make it so that when you open up the batch file, it wont show the commands
echo - any text following this will be shown on the Command Prompt window
ex. echo Hello World (see pic)
Pause - causes the batch file to stop. Displays "Press any key to continue..."
echo. - creates a blank line
@echo off > - starts a new file
ex. @echo off > hosts would create file called "hosts"
If you add .txt at the end, it would make a text file. So @echo off > test.txt would make a text version of the file
>> hosts - used at the end of a line. This causes the text on that line to be added to the file "hosts"
If you made the file something like test.txt in the previous command (@echo off >) then you would put that in this command every time you use it
@echo off test.txtecho Hi >> test.txtcd - change the directory
cd\ - change the directory to the main drive (ie. C:\)
cd\%windir% - change the directory to your WINDOWS folder
del - deletes a file
attrib - changes the attributes of a file (hidden/read-only etc)
Step 2: Hosts File Basics
This is generally located in C:\WINDOWS\SYSTEM32\DRIVERS\ETC
You will have to open it with a text editing program, preferably notepad. Once you've done this you can take a look at it and see how to use it.
The big box below is how windows tries to explain how this file works. To make it simple, find an IP address for another site and then type the site you want to redirect from. To block sites just use 0.0.0.0 and then type the site you want to block next to it.
ex. 0.0.0.0 google.com
This tells your computer to send google.com to 0.0.0.0 which then says that it can't connect.
Step 3: Starting the Batch
@echo offAs explained earlier, this will keep your commands from being seen on the command prompt screen.
Now you want to navigate to the folder with your hosts file to make all of the rest of the coding simpler. Again, cd\ will bring your batch file back to your main drive...so type that into your notepad file. At this point you can do everything all at once or one step at a time. You are trying to get your batch file to point at WINDOWS\SYSTEM32\DRIVERS\ETC
cd WINDOWS\SYSTEM32\DRIVERS\ETCMultiple Steps
cd WINDOWScd SYSTEM32cd DRIVERScd ETC
Step 4: A Clean Slate
Ok so to start a clean slate, I delete the original hosts file. Just to play it safe I change the attributes of the file as well. Again, this is just personal preference so that I don't get an error message. To do this type
attrib -r -hdel hostsThe attrib command lets you manipulate a file's attributes and the -r command makes it so that a file isn't read-only. The -h makes sure that the file isn't hidden. The del command obviously deletes the file.
Step 5: Making the File Look Real
You need to type the echo command to be able to make text appear from this point on. This is shown in the included file so that you can see what I am talking about. Also, as mentioned earlier, echo. provides you with a blank line.
From this step on, everything will be what you want it to be. I will show you what you need to do and then it's your choice how you want to use it.
Step 6: The Easy Part
Here is where you decide what site you want to block. For this example I will use google.
Like I mentioned in the last step, you start with echo. Then you put a space, and then to block the site type the IP 127.0.0.1 or 0.0.0.0
Once that is all done, put a space and then the site you wish to block
echo 0.0.0.0 google.com
Just like that. It's that simple. For added blocking I also do it with www in front.
echo 0.0.0.0 www.google.comI do this because I found that if you block google.com and someone tries to use www.google.com it still works for some strange reason. The code, with these two then looks like:
echo 0.0.0.0 google.comecho 0.0.0.0 www.google.com
You can then repeat this for any site that you wish to block
Step 7: Finishing Up
attrib +r +hat the end of your batch file.
Ok so once you are done you click Save As, and pick All Files. Type in the name of your file and then add .bat at the end. Once that is done, you can double click on it and it will run the batch for you.
I will attach my block list and then a fix for it as well. The fix works for any block list and it creates a hosts file that looks exactly like the original
The fun part is tricking your friends into opening the file and then letting them figure out whats wrong.
It's best if the browser is closed right after using the batch that way when you open it, the sites will be blocked. If you choose not to close the browser, it will take a few minutes for the blocking to take effect