Introduction: Make a Self-Writing Site Blocker

Picture of Make a Self-Writing Site Blocker

This will make a batch file that creates the hosts file to block any sites you don't like. If you can trick your friends then you can even block sites they use just for fun.

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

Picture of Batch Basics
Ok so it does help to know some batch file basics. Right now I will explain what I can.

@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
ex.
@echo off test.txtecho Hi >> test.txt
cd - 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

Picture of Hosts File Basics

Ok. Before moving on, I suggest you look at your hosts file.

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

Ok so using the basics from earlier, it is possible to write a batch file that will automatically write the hosts file to be able to block a site. You open notepad and you should type in
@echo off
As 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

One Step
cd WINDOWS\SYSTEM32\DRIVERS\ETC
Multiple Steps
cd WINDOWScd SYSTEM32cd DRIVERScd ETC

Step 4: A Clean Slate

Ok so now you have your batch file pointed to the right folder. From here I like to start things clean...so I delete the file. You don't have to if you don't want to.

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 hosts
The 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

Another preference I have is making the file look authentic. So now that I have deleted the file, I recreate it exactly the way it was before deletion. The code up to this point is attached at the bottom.

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

Now that you have most of the coding done, the rest is quite simple.

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.com
I 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

At the end, I change the attributes of the hosts file again to be read-only and hidden. To do this just type
attrib +r +h
at 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.

Added Note:
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

Comments

account3r2 (author)2010-12-23

how do you un block it?

macweirdo (author)2008-11-03

Also, you can type "pause >NUL" (without the quotes) to give a hidden pause. And to answer the "www.google.com" and "google.com" blocking question, to block both, type (star). and the website's name to block (anything).google.com (including google.com).

Scytheon3 (author)macweirdo2009-07-22

Does this mean you could put echo 0.0.0.0 *.*.* to block every site on the internet

Archive555 (author)Scytheon32009-12-08

Not quite sure if that'd work, but if it did, you could just use an asterisk by itself
echo *
Rather than
echo *.*.*.*

elmynase (author)2009-01-14

what if instead of putting "0.0.0.0", you put the IP adress of an other site, like say youtube.com If you type "www.google.com", will it send you to youtube.com ? thanks any way good instructable

Serneum (author)elmynase2009-01-14

Exactly. You would open up command prompt, type in ping youtube.com and instead of 0.0.0.0, you would put the IP address of youtube (which you get from the ping)

Arbitror (author)2008-12-06

Not working!

macweirdo (author)2008-11-03

sry, its (star)(dot). I messed up the comment thing.

trumpkin (author)2008-03-05

when i try to open the batch file it closes right away, whats up.

Neodudeman (author)2008-02-22

Did I ever say "Thanks for the mention! =D" ?

Because I meant to, lol.

I HACK (author)2008-02-02

how to undo pleez

Serneum (author)I HACK2008-02-02

In the last step theres a file called HostsFix

hq (author)2007-12-28

del hosts this does not work the user has to push Y enter it say´s would you like to deleate this folder this might work! del hosts-Y

Serneum (author)hq2007-12-28

I've tested it on my computer and it would delete the file

moomoocows (author)2007-07-23

i'm having trouble opening the hosts file i open it with note pad and all i get is a line of numbers with a couple periods

THE NEWBIE (author)2007-07-15

can u ples make a step that has all u need to type on it?

duct tape (author)2007-06-28
This is also the reason for many of those 'I can hack' videos. They show you the web site, then they turn the camera off. Then they edit the hosts file, like this:
127.0.0.1         www.site.com127.0.0.1         site.com
So that it points the browser to your own computer to look for the 'index.htm' file, and displays that instead of the real site. So you could make a page where it says "Access: DENIED" really big.
hg341 (author)2007-06-21

who hoo!!!!!!we i love this

josh92176 (author)2007-06-20

Great, not only does this tell you how to make a self writing site blocker it also explains what all the commands do. cool :-)

About This Instructable

13,113views

22favorites

License:

More by Serneum:Make a Self-Writing Site Blocker
Add instructable to: