views:

282

answers:

2

Hi

I am developing a windows application to block the websites from a computer using DotNet windows programming.I found some results to block an url but not for a website. That is I have to block complete website not a single url.

So can some one help me to solve this problem

Thanking You

Chaithanya

A: 

Why are you using an application running on the local machine to do this? It doesn't make much sense. This is done through a corporate proxy, generally.

You may edit the

c:\windows\system32\drivers\etc\hosts

File to resolve a domain name to '127.0.0.1', instead of what it would normally do, to stop it being visible in that fashion. But it's better to do it properly.

Please describe what you're trying to do in more detail.

Noon Silk
I wouldn't use localhost, 'just in case'. Using 127.0.0.0 or some other invalid IP address would probably be safer.
Matthew Scharley
This is also not granular like chaithu wanted, ie. s/he wants to block http://example.com/foo but not http://example.com/bar (atleast from what I understood of it). I do agree that a proxy off the local PC is the way to go about it though.
Matthew Scharley
Matthew: You misread, see his post: ' ... that is I have to block complete website not a single url.'
Noon Silk
Actually I am developing a software to run on the server and block the websites on the client systems using the client system name.My application is if i block www.google.com,entire website should be blocked i.e if user types www.google.co.in,it should not show the webpage of google
chaithu
@chaithu: `www.google.co.in` is **not** the same website as `www.google.com`, nor is `www.amazon.org` the same website as `www.amazon.com`. Besides, why would a client PC bother with your server?
MSalters
+1  A: 

It sounds like you want the services of the System.Uri class (http://msdn.microsoft.com/en-us/library/system.uri.aspx). I'm guessing that at some point you have to decide whether or not you are going to allow or disallow a request based on the URI, in which case you will want logic similar to the following:

Uri uri = new Uri("http://www.google.co.uk/somepage.html");
if (uri.Host.ToLower().EndsWith("google.co.uk"))
{
    // Do something
}

Experiment with something like that. Things to note are that:

  • If you check to see if the host equals "www.google.co.uk" then this would still mean that other subdomains (e.g. "www3.google.co.uk") wouldnt be blocked.
  • If you check to see if the host contains "google.co.uk" then you risk blocking others whose subdomain contains (for stupid reasons) someone elses url, for example "google.co.uk.MyDomain.co.uk" which is still a valid (if stupid) subdomain under the "MyDomain.co.uk" domain.
Kragen
And of course, this only blocks requests that happen to go through this check. I.e. it's not a computer-wide check.
MSalters
Another thing to note is that the `EndsWith()` check you have made, will also block "notgoogle.co.uk".
troethom