Think in the lines of Parental control application where we need to block certain websites from being accessed. To make it harder, this will be a Windows application where user can configure the sites to be blocked and unblocked.
Let's start thinking of what we can do to achieve this.
Should we monitor the incoming/outgoing packets to intercept the source/destination ? Wow, that would be fun, interesting - Hacking! No we should not do this or is this even possible?. Let's see the other options.
Should we intercept the browser object and then check the URL being used ? We can but not a full proof method. We will have to continuously check for the browser to see if a Blocked URL is being accessed. Not at all an option.
So, what do we do ?
Don't panic. A simple approach can be used to achieve this.
There is a file "Network host file" present on the system. This file contains DNS Maps for the system used by Windows. It can be found on your machine at for example, "C:\WINDOWS\SYSTEM32\DRIVERS\ETC\HOSTS" (i.e. %SystemRoot%\System32\Drivers\etc). By default this file will contain an entry like this,
127.0.0.1 localhost
This entry means, resolve localhost to 127.0.0.1.
The way to block website is to add a new entry to this list like,
127.0.0.1 www.WebsiteToBeBlocked.com
Note: This is a windows file so it might be readonly and might need permissions. By adding the entry we are basically looping the call www.WebsiteToBeBlocked.com back to local machine and since the local machine won't be a webserver this call will fail.
So the windows application for Parental control will just have to open the file for editing and add the particular sites entry at the end of it i.e. append the entry.
//demonstration code string hostfile = "C:\\Windows\\System32\\drivers\\etc\\hosts"; //hardcoding for demonstration purpose string newEntry = Environment.NewLine + "127.0.0.1 theSiteToBlock.com"; //hardcoding for demonstration purpose
StreamWriter writer = new StreamWriter(hostfile, true); //The second parameter is true to open the file in append mode. writer.Write(newEntry); writer.Close();
To unblock the site, delete its corresponding entry from the file.
Have fun.
For more details, visit http://abitsmart.com/?p=117
|
No responses found. Be the first to respond and make money from revenue sharing program.
|