Click here to Skip to main content
15,889,879 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi Friends

I need to block particular websites please help me with VB.NET code to block IP address of particular sites.

Thank you
Posted
Updated 4-Dec-09 8:43am
v2

Hello

I think if you can try the following code

C#
private void button1_Click(object sender, EventArgs e)
        {
            String path = @"C:\Windows\System32\drivers\etc\hosts";
            StreamWriter sw = new StreamWriter(path, true);
            String sitetoblock = "\n 127.0.0.1 google.com";
            sw.Write(sitetoblock);
            sw.Close();
            MessageBox.Show("Site Blocked");
        }
    }
 
Share this answer
 
v2
Irrespective of the programming language used, you could add entries to the hosts file[^] such that a specific URL is blocked (by make it point to the local host).

So, it would basically be a file write operation, but your program will require administrative privileges to run.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900