DNS Cache to Static Move Script

one day, may help you :wink:

# DNS Cashe To Static Moving Script 
# Rename script to "DNS-CTS" 
# Moving all alias of host. 
{ 
:if ([:len [/system script job find script="DNS-CTS"]]!=1) do={:log warning "DNS-CTS in processing...";} else={ 
     :local CFlush false;
     :foreach Crec in=[/ip dns cache all find where ( ( (type="A") || (type="AAAA") || (type="CNAME") ) && (static=no) )] do={ 
         :local Cname [/ip dns cache get number=$Crec name]; 
         :local Cdata "";  
         :if ([/ip dns cache all get $Crec type]="CNAME") do={ 
         :set $CFlush true; 
         :set $Cdata [:resolve $Cname]; } else={ 
         :set $Cdata [/ip dns cache get number=$Crec address]; } 
         :do {/ip dns static add name=$Cname address=$Cdata disabled=yes } on-error={ 
         :log error message="Moving failure of: Host=$Cname Address=$Cdata"; }
         :delay 500ms;
     } 

     :foreach Srec in=[/ip dns static find where disabled=yes] do={ 
         :local Sname [/ip dns static get number=$Srec name]; 
         :local Sdata [/ip dns static get number=$Srec address];
         :do {/ip dns static set $Srec disabled=no } on-error={ 
         :log error message="Removing duplication exist: Host=$Sname Address=$Sdata;"; 
         :do {/ip dns static remove numbers=$Srec } on-error={ 
         :log error message="Removing duplication of Host=$Sname Address=$Sdata; failed";} } 
         :delay 500ms;
	 } 

     :if ( $CFlush=true ) do={/ip dns cache flush; :log warning message="DNS Cache Flush Done"; } 
     :delay 500ms; 
} 
}

more likely, one day, it will cause you hard to debug problems!
readers are warned - only use when you know what you are breaking…

yes i mean for debug purpose only, that’s why i said one day not every day
thanks guru :smiley: