views:

447

answers:

4

I need a way to programaticaly block and then later unblock specific websites based on their domain names. I only need to block browsers (so http & https would be sufficient, I guess?) but not just Internet Explorer, it should also work for anyone trying to run Chrome or Firefox too.

This needs to work on Windows XP and be usable from a .NET program (Vb.net or C#).

(ps., I had found this question: http://stackoverflow.com/questions/868054/how-to-unblock-website-which-is-blocked-using-c which seems to be saying the same thing, however at the time I could not understand it. Now I see it, thanks all.) Thanks,

+1  A: 

A down and dirty way would be to dynamically update the hosts file.

c:\Windows\System32\drivers\etc\hosts

jasonlaflair
OK, I have read the doc on the hosts file, but it does not say how to use it to block a site?
RBarryYoung
+1  A: 

You could add entries to the Hosts.ini file to achieve this. It would only work on Windows. Have a look here link text

Peter
OK, I have read the doc on the hosts file, but it does not say how to use it to block a site?
RBarryYoung
+4  A: 

This line in the hosts file will redirect to localhost. Though I have nothing against Nascar ;)

127.0.0.1       www.nascar.com

Block websites using a hosts file.

jjclarkson
Sweet! I just tested it and it worked great!
RBarryYoung
+1  A: 

First off, know that you need to be an Administrator to do this stuff.

Well, you can just add a line to the hosts file in ( c:\Windows\System32\drivers\etc\hosts ) with the site you want, such as:

127.0.0.1 www.example.com

After that is done, just run the following command:

ipconfig /flushdns

Some web browsers, including Firefox, will also have to be restarted as well.

To unblock a blocked site, just delete it's entry from the hosts file, or place a # sign at the beginning of it.

MiffTheFox