Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # DNS blacklist file
- :global dns_blacklist "dns_blacklist.txt";
- # if you're using static DNS records with '127.0.0.1':
- # change this value to something else (must be 'invalid' too :) )
- :global dns_blackhole "127.0.0.1";
- # http://pastebin.com/YXYrQVsH
- #strreplace
- # 1 - where
- # 2 - what
- # 3 - with
- :global strreplace do={
- :local l1 [:len $1];
- :local l2 [:len $2];
- :local l3 [:len $3];
- :local lr 0;
- :local i 0;
- :local k -1;
- :local r $1;
- :do {
- :set lr [:len $r];
- :set i [:find $r $2 $k];
- :if ($i != nil) do={
- :set r ([:pick $r -1 $i] . $3 . [:pick $r ($i + $l2) $lr]) ;
- :set k ($i + $l3 - 1);
- }
- } while=($i < $l1)
- :return $r;
- }
- #dnsrenew
- # reads file "$dns_blacklist" (list of DNS names, one per line)
- # and bans out DNS requests to them;
- :global dnsrenew do={
- :local cC [/file get [/file find name=$dns_blacklist ] contents];
- :local cL [ :len $cC ];
- :local le0 0;
- :local le1 -1;
- :local nameF "";
- :local nameRE "";
- /ip dns static remove [/ip dns static find where address=$dns_blackhole];
- :delay;
- :do {
- :set le0 [:find $cC "\n" $le1];
- :set nameF [:pick $cC $le1 $le0];
- :set le1 ($le0 + 1);
- :if ($nameF != nil) do={
- :set nameRE (".*\\." . [ $strreplace $nameF "." ("\\".".")]);
- /ip dns static add address=$dns_blackhole name=$nameF;
- /ip dns static add address=$dns_blackhole name=$nameRE;
- :put ($nameF . "\t" . $nameRE);
- }
- } while=($le0 < $cL)
- :delay;
- /ip dns cache flush;
- }
- # call dnsrenew()
- $dnsrenew
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement