Created
June 2, 2015 08:39
-
-
Save jgrossiord/0bd525974a5ec059adba to your computer and use it in GitHub Desktop.
Mikrotik script generate address list from DNS cache entries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
: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 "facebook" -1] >= 0) || ([:find $cacheName "outlook" -1] >= 0)) do={ | |
:local tmpAddress [/ip dns cache get $i address] ; | |
:put $cacheName; | |
: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=youtube_dns_ips 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=youtube_dns_ips comment=$cacheName; | |
} | |
} | |
} | |
} |
does not work on RouterOS v7
does not work on RouterOS v7
See ZloyXEP post. This work.
I somewhat reworked the script by @ZloyXEP while reintroducing the in-script filtering from the original script to combat big CPU usage spikes, which, in my understanding, can potentially kill the CPU over time or lower its lifespan because of the expansion and contraction of silicon. The reworked script can be found here.
Edit: I forgot forks are a thing. Oh well. Sorry.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
:foreach i in=[/ip dns cache find where (name~"youtube") or (name~"ytstatic") or (name~"ytimg") or (name~"youtube") or (name~"googlevideo.com")] do={
:local cacheName [/ip dns cache all get $i name];
:local cacheType [/ip dns cache all get $i type];
delay delay-time=10ms
:if ($cacheType="A") do={
:local cacheData [/ip dns cache all get $i data];
:if ( [/ip firewall address-list find where address=$cacheData]="") do={
:put ("add: $cacheName $cacheType $cacheData");
/ip firewall address-list add address=$cacheData comment=$cacheName timeout=2d list=youtube_dns_ips
}
}
}