如何在C#中动态阻止网站?

时间:2011-04-13 20:09:10

标签: c# url filter block

我想从用C#编写的Windows服务中动态阻止某些URL。我不想通过写入hosts文件来做到这一点。

例如,我想阻止网址http://example.com(在所有浏览器中),但也会阻止http://example.com/another从早上7点到早上8点。

这可能,我该怎么办?

祝你好运, 安德鲁

2 个答案:

答案 0 :(得分:2)

您可以使用Windows Firewall API。请参阅John Cole撰写的文章 Managed classes to view/manipulate the Windows Firewall

答案 1 :(得分:-2)

现在,我展示了块的概念。谷歌网站。我希望这个解决方案可以帮到你。

 private void BlockWebsite_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");
    }
}