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

| 我想动态地阻止使用C#编写的Windows Service中的某些URL。我不想通过写入主机文件来做到这一点。 例如,我想阻止URL“ 0”(在所有浏览器中),但还要阻止“ 1”从上午7点到晚上8点。 这可能吗,我该怎么办? 最好的祝福, 安德鲁     
已邀请:
您也许可以使用Windows防火墙API。请参阅John Cole的文章“托管类以查看/操作Windows防火墙”。     
现在,我展示块的概念。谷歌网站。希望这个解决方案能对您有所帮助。
 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\");
    }
}
    

要回复问题请先登录注册