User Tools

Site Tools


networking:router:mikrotik_resolve

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
networking:router:mikrotik_resolve [2017/12/05 09:46]
gcooper created
networking:router:mikrotik_resolve [2017/12/05 09:57] (current)
gcooper
Line 8: Line 8:
  
 <note warning>As written, this script will not resolve multiple hostnames.</note> <note warning>As written, this script will not resolve multiple hostnames.</note>
 +
 +===== Example Scripts =====
 +
 +==== resolve_delivery.antispamcloud.com ====
 +
 +:!: This script is intended to resolve multiple hostnames in the ''source='' line.
 +
 +<file>
 +/system script
 +add comment="Resolve DNS Hostname to Address List" name=resolve_delivery.antispamcloud.com owner=admin \
 +    policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
 +    source=":local hosts {\"delivery.antispamcloud.com\"}\r\
 +    \n:foreach k,v in=\$hosts do={\r\
 +    \n  :log info \"Doing \$v\"\r\
 +    \n  :local listname \$v\r\
 +    \n  :resolve \$v\r\
 +    \n  :local iscname [/ip dns cache all find where name=\$v and type=\"CNAME\"]\r\
 +    \n  :if (\$iscname != \"\") do={\r\
 +    \n    :local newname [/ip dns cache all get \$iscname data]\r\
 +    \n    :log info \"\$v is CNAME to \$newname\"\r\
 +    \n    :set v \$newname\r\
 +    \n  }\r\
 +    \n  :resolve \$v\r\
 +    \n  /ip firewall address-list remove [/ip firewall address-list find where list=\$listname]\r\
 +    \n  :foreach i in=[/ip dns cache all find where name=\$v and type=\"A\"] do={\r\
 +    \n    :local ipaddr [/ip dns cache all get \$i data]\r\
 +    \n    /ip firewall address-list add list=\$listname address=\$ipaddr comment=\$v\r\
 +    \n    :log info \"IP address: \$ipaddr\"\r\
 +    \n  }\r\
 +    \n  /ipv6 firewall address-list remove [/ipv6 firewall address-list find where list=\$listname]\r\
 +    \n  :foreach i in=[/ip dns cache all find where name=\$v and type=\"AAAA\"] do={\r\
 +    \n    :local ipaddr [/ip dns cache all get \$i data]\r\
 +    \n    /ipv6 firewall address-list add list=\$listname address=\$ipaddr comment=\$v\r\
 +    \n    :log info \"IPv6 address: \$ipaddr\"\r\
 +    \n  }\r\
 +    \n}\r\
 +    \n:log info \"end\""
 +</file>
networking/router/mikrotik_resolve.1512492367.txt.gz · Last modified: 2017/12/05 09:46 by gcooper