以临时阻止特定网站的编程方式?

时间:2021-12-01 17:43:03

I need a way to programaticaly block and then later unblock specific websites based on their domain names. I only need to block browsers (so http & https would be sufficient, I guess?) but not just Internet Explorer, it should also work for anyone trying to run Chrome or Firefox too.

我需要一种方法来programaticaly阻止,然后根据他们的域名解锁特定的网站。我只需要阻止浏览器(所以http和https就足够了,我猜?)但不仅仅是Internet Explorer,它也适用于任何试图运行Chrome或Firefox的人。

This needs to work on Windows XP and be usable from a .NET program (Vb.net or C#).

这需要在Windows XP上运行,并且可以从.NET程序(Vb.net或C#)使用。

(ps., I had found this question: How to unblock website which is blocked, using C#? which seems to be saying the same thing, however at the time I could not understand it. Now I see it, thanks all.) Thanks,

(ps。,我发现了这个问题:如何解锁被阻止的网站,使用C#?这似乎是在说同样的事情,但当时我无法理解它。现在我看到了,谢谢所有。)谢谢,

4 个解决方案

#1


This line in the hosts file will redirect to localhost. Though I have nothing against Nascar ;)

hosts文件中的这一行将重定向到localhost。虽然我没有反对纳斯卡;)

127.0.0.1       www.nascar.com

Block websites using a hosts file.

使用hosts文件阻止网站。

#2


A down and dirty way would be to dynamically update the hosts file.

一种向下和脏的方式是动态更新主机文件。

c:\Windows\System32\drivers\etc\hosts

#3


You could add entries to the Hosts.ini file to achieve this. It would only work on Windows. Have a look here link text

您可以向Hosts.ini文件添加条目以实现此目的。它只适用于Windows。看看这里链接文字

#4


First off, know that you need to be an Administrator to do this stuff.

首先,要知道你需要成为管理员才能做到这一点。

Well, you can just add a line to the hosts file in ( c:\Windows\System32\drivers\etc\hosts ) with the site you want, such as:

好吧,您只需在(c:\ Windows \ System32 \ drivers \ etc \ hosts)中的主机文件中添加一行,即可以使用您想要的站点,例如:

127.0.0.1 www.example.com

After that is done, just run the following command:

完成后,只需运行以下命令:

ipconfig /flushdns

Some web browsers, including Firefox, will also have to be restarted as well.

某些Web浏览器(包括Firefox)也必须重新启动。

To unblock a blocked site, just delete it's entry from the hosts file, or place a # sign at the beginning of it.

要取消阻止被阻止的站点,只需从hosts文件中删除它的条目,或在其开头放置一个#符号。

#1


This line in the hosts file will redirect to localhost. Though I have nothing against Nascar ;)

hosts文件中的这一行将重定向到localhost。虽然我没有反对纳斯卡;)

127.0.0.1       www.nascar.com

Block websites using a hosts file.

使用hosts文件阻止网站。

#2


A down and dirty way would be to dynamically update the hosts file.

一种向下和脏的方式是动态更新主机文件。

c:\Windows\System32\drivers\etc\hosts

#3


You could add entries to the Hosts.ini file to achieve this. It would only work on Windows. Have a look here link text

您可以向Hosts.ini文件添加条目以实现此目的。它只适用于Windows。看看这里链接文字

#4


First off, know that you need to be an Administrator to do this stuff.

首先,要知道你需要成为管理员才能做到这一点。

Well, you can just add a line to the hosts file in ( c:\Windows\System32\drivers\etc\hosts ) with the site you want, such as:

好吧,您只需在(c:\ Windows \ System32 \ drivers \ etc \ hosts)中的主机文件中添加一行,即可以使用您想要的站点,例如:

127.0.0.1 www.example.com

After that is done, just run the following command:

完成后,只需运行以下命令:

ipconfig /flushdns

Some web browsers, including Firefox, will also have to be restarted as well.

某些Web浏览器(包括Firefox)也必须重新启动。

To unblock a blocked site, just delete it's entry from the hosts file, or place a # sign at the beginning of it.

要取消阻止被阻止的站点,只需从hosts文件中删除它的条目,或在其开头放置一个#符号。