:global GlobalFuncReady false;
# Git commit id & info, expected configuration version
-:global CommitId "main/329/d1d1be7e";
+:global CommitId "main/330/d3b01a82";
:global CommitTAG "unknown";
-:global CommitInfo "Autocommit in repo: ros.vados.ru, generated by owner: root, in 02:55:02 01.05.2026.";
+:global CommitInfo "Autocommit in repo: ros.vados.ru, generated by owner: root, in 03:00:02 01.05.2026.";
# The variables are received right here.
:global GlobalConfVersion 138;
--- /dev/null
+:global ListName
+:global Servers
+:global Done
+
+#has $Done been initialized?
+:if ([:typeof $Done] != "boolean") do={
+ :set Done true;
+}
+
+#make sure previous runs have finished
+while (!$Done) do={
+ :nothing;
+}
+
+#block any other runs
+:set Done false;
+
+#delete old address lists
+:foreach aListItem in=[/ip firewall address-list find list=$ListName] do={
+ /ip firewall address-list remove $aListItem;
+}
+
+:foreach aServer in=$Servers do={
+#force the dns entries to be cached
+ :do {
+ :resolve $aServer;
+ } on-error={
+ :log error "dns resolve failure [ ip - resolve ip ]"
+ }
+
+ :foreach dnsRecord in=[/ip dns cache all find where (name=$aServer)] do={
+#if it's an A records add it directly
+ :if ([/ip dns cache all get $dnsRecord type]="A") do={
+ :local newAddress [/ip dns cache all get $dnsRecord data];
+ :do {
+ /ip firewall address-list add list=$ListName address=$newAddress comment=$aServer;
+ } on-error={
+ :log error "error when adding ip to list: $newAddress"
+ }
+ }
+
+#if it's a CNAME follow it until we get A records
+ :if ([/ip dns cache all get $dnsRecord type]="CNAME") do={
+ :local cname;
+ :local nextCname
+ :set cname [/ip dns cache all find where (name=$aServer && type="CNAME")];
+ :set nextCname [/ip dns cache all find where (name=[/ip dns cache all get $cname data] && type="CNAME")];
+
+ :while ($nextCname != "") do={
+ :set cname $nextCname;
+ :set nextCname [/ip dns cache all find where (name=[/ip dns cache all get $cname data] && type="CNAME")];
+ }
+
+#add the a records we found
+ :foreach aRecord in=[/ip dns cache all find where (name=[/ip dns cache all get $cname data] && type="A")] do={
+ :do {
+ /ip firewall address-list add list=$ListName address=[/ip dns cache all get $aRecord data] comment=$aServer;
+ } on-error={
+ :log error "error when adding ip to list: $newAddress"
+ }
+ }
+ }
+ }
+}
+
+#allow other scripts to call this
+:set Done true
\ No newline at end of file