Skip to content

Instantly share code, notes, and snippets.

@jgrossiord
Created June 2, 2015 08:39
Show Gist options
  • Save jgrossiord/0bd525974a5ec059adba to your computer and use it in GitHub Desktop.
Save jgrossiord/0bd525974a5ec059adba to your computer and use it in GitHub Desktop.
Mikrotik script generate address list from DNS cache entries
: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;
}
}
}
}
@Dinollee
Copy link

Dinollee commented Oct 9, 2021

С обновлением Microtik cкрипт уже не работает помогите исправить (

@ZloyXEP
Copy link

ZloyXEP commented May 26, 2022

С обновлением Microtik cкрипт уже не работает помогите исправить (

: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
}
}
}

@giveittome
Copy link

does not work on RouterOS v7

@Dinollee
Copy link

does not work on RouterOS v7

See ZloyXEP post. This work.

@Nullcaller
Copy link

Nullcaller commented Mar 30, 2023

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