这个脚本是有用的,如果你想阻止某些网站,但你不希望使用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=[/ip dns cache find] do={
:local bNew "true";
:local cacheName [/ip dns cache all get $i name] ;
# :put $cacheName; :if (([:find $cacheName "rapidshare"] != 0) || ([:find $cacheName "youtube"] != 0)) do={ :local tmpAddress [/ip dns cache get $i address] ;
# :put $tmpAddress; # if address list is empty do not check
:if ( [/ip firewall address-list find ] = "") do={
:log info ("added entry: $[/ip dns cache get $i name] IP $tmpAddress");
/ip firewall address-list add address=$tmpAddress list=restricted comment=$cacheName;
} else={
:foreach j in=[/ip firewall address-list find ] do={
:if ( [/ip firewall address-list get $j address] = $tmpAddress ) do={
:set bNew "false";
}
}
:if ( $bNew = "true" ) do={
:log info ("added entry: $[/ip dns cache get $i name] IP $tmpAddress");
/ip firewall address-list add address=$tmpAddress list=restricted comment=$cacheName;
}
}
}
} |