Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sgeto/ae4a941756137474fd78ececb279d45b to your computer and use it in GitHub Desktop.
Save sgeto/ae4a941756137474fd78ececb279d45b 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;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment