RBarryYoung
RBarryYoung

Reputation: 56715

Programmatic way to temporarily block specific Web Sites?

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

Upvotes: 2

Views: 3131

Answers (4)

MiffTheFox
MiffTheFox

Reputation: 21555

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.

Upvotes: 1

jjclarkson
jjclarkson

Reputation: 5964

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.

Upvotes: 4

Peter
Peter

Reputation: 1801

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

Upvotes: 1

Joshua Turner
Joshua Turner

Reputation: 1049

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

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

Upvotes: 1

Related Questions