root_main 发表于 2011-5-24 15:58:18

禁止访问特定网站

这个脚本是有用的,如果你想阻止某些网站,但你不希望使用Web代理。 这个例子中查找DNS缓存项“免费电子”和“YouTube”的,并增加了IPS来解决命名为“限制”之列。
在开始之前,你必须设置路由器来捕捉所有DNS请求:
[*]/ip firewall nat[*]add action=redirect chain=dstnat comment=DNS dst-port=53 protocol=tcp to-ports=53[*]add action=redirect chain=dstnat dst-port=53 protocol=udp to-ports=53
[*]/ip firewall filter[*]add chain=forward dst-address-list=restricted action=drop
现在我们可以写一个脚本,把它加在计划任务,每30秒运行一次。

:foreach i in= do={
    :local bNew "true";
    :local cacheName ;
#    :put $cacheName;    :if (([:find $cacheName "rapidshare"] != 0) || ([:find $cacheName "youtube"] != 0)) do={      :local tmpAddress ;
#      :put $tmpAddress;# if address list is empty do not check
      :if ( = "") do={
            :log info ("added entry: $ IP $tmpAddress");
            /ip firewall address-list add address=$tmpAddress list=restricted comment=$cacheName;
      } else={
            :foreach j in= do={
                :if ( = $tmpAddress ) do={
                  :set bNew "false";
                }
            }
            :if ( $bNew = "true" ) do={
                :log info ("added entry: $ IP $tmpAddress");
                /ip firewall address-list add address=$tmpAddress list=restricted comment=$cacheName;
            }
      }
    }
}
页: [1]
查看完整版本: 禁止访问特定网站