Community discussions

MikroTik App
 
User avatar
ADahi
Member Candidate
Member Candidate
Topic Author
Posts: 209
Joined: Thu Sep 21, 2017 7:16 pm
Location: Iraq, Ninavah
Contact:

DNS Cache to Static Move Script

Mon Mar 19, 2018 9:18 pm

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; 
} 
} 
Last edited by ADahi on Tue Mar 20, 2018 11:00 am, edited 1 time in total.
 
pe1chl
Forum Guru
Forum Guru
Posts: 10196
Joined: Mon Jun 08, 2015 12:09 pm

Re: DNS Cache to Static Move Script

Mon Mar 19, 2018 9:52 pm

more likely, one day, it will cause you hard to debug problems!
readers are warned - only use when you know what you are breaking...
 
User avatar
ADahi
Member Candidate
Member Candidate
Topic Author
Posts: 209
Joined: Thu Sep 21, 2017 7:16 pm
Location: Iraq, Ninavah
Contact:

Re: DNS Cache to Static Move Script

Mon Mar 19, 2018 11:46 pm

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

Who is online

Users browsing this forum: No registered users and 23 guests