Make a Self-Writing Site Blocker




Introduction: 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

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
@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

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 and then type the site you want to block next to it.


This tells your computer to send to 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 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
Multiple Steps

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 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 or

Once that is all done, put a space and then the site you wish to block

Just like that. It's that simple. For added blocking I also do it with www in front.
I do this because I found that if you block and someone tries to use it still works for some strange reason. The code, with these two then looks like:
echo google.comecho

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

Be the First to Share


    • Arduino Contest

      Arduino Contest
    • Colors of the Rainbow Contest

      Colors of the Rainbow Contest
    • Barbecue Speed Challenge

      Barbecue Speed Challenge



    12 years ago on Introduction

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


    Reply 11 years ago on Introduction

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


    Reply 11 years ago on Introduction

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


    12 years ago on Step 6

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


    Reply 12 years ago on Step 6

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


    13 years ago on Step 5

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


    13 years ago on Introduction

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

    Because I meant to, lol.


    Reply 13 years ago on Introduction

    In the last step theres a file called HostsFix


    13 years ago on Introduction

    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

    duct tape
    duct tape

    13 years ago on Introduction

    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:
    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.

    14 years ago on Introduction

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