Community discussions

MikroTik App
 
CBE
just joined
Topic Author
Posts: 13
Joined: Sat Apr 18, 2020 4:34 am

Script to collect IPs from the DNS cache on address lists executes just first block of code.

Sat Apr 18, 2020 4:59 am

Hello. The script is creating address lists just for the first block (amazonaws list), even though the DNS cache contains entries for the other domain keywords. Running the code directly from the Scheduler (the Scheluler doesn't run the script if being called as a separate script) on RouterOS 6.45.8 I'll reallly appreciate any help.
###### Use DNS Entrys and add Address to the Firewall Address-list #
:foreach i in=[/ip dns cache all find where (name~"amazonaws") && (type="A") && (data!="240.0.0.1")] do={
 :local tmpAddress [/ip dns cache get $i address];
delay delay-time=3000ms
# prevent script from using all cpu time #
 :if ( [/ip firewall address-list find where address=$tmpAddress] = "") do={ 
 :local cacheName [/ip dns cache get $i name] ;
 :log info ("added entry: $cacheName $tmpAddress");
 /ip firewall address-list add address=$tmpAddress list=amazonaws-hosts; } }
#
###### Use DNS Entrys and add Address to the Firewall Address-list #
:foreach i in=[/ip dns cache all find where (name~".bbcollab.com") && (type="A") && (data!="240.0.0.1")] do={
 :local tmpAddress [/ip dns cache get $i address];
delay delay-time=3000ms
# prevent script from using all cpu time #
 :if ( [/ip firewall address-list find where address=$tmpAddress] = "") do={ 
 :local cacheName [/ip dns cache get $i name] ;
 :log info ("added entry: $cacheName $tmpAddress");
 /ip firewall address-list add address=$tmpAddress list=blackboard-hosts; } }
#
###### Use DNS Entrys and add Address to the Firewall Address-list #
:foreach i in=[/ip dns cache all find where (name~".bbcollabcloud.com") && (type="A") && (data!="240.0.0.1")] do={
 :local tmpAddress [/ip dns cache get $i address];
delay delay-time=3000ms
# prevent script from using all cpu time #
 :if ( [/ip firewall address-list find where address=$tmpAddress] = "") do={ 
 :local cacheName [/ip dns cache get $i name] ;
 :log info ("added entry: $cacheName $tmpAddress");
 /ip firewall address-list add address=$tmpAddress list=blackboard-hosts; } }
#
###### Use DNS Entrys and add Address to the Firewall Address-list #
:foreach i in=[/ip dns cache all find where (name~".bbcollab.cloud") && (type="A") && (data!="240.0.0.1")] do={
 :local tmpAddress [/ip dns cache get $i address];
delay delay-time=3000ms
# prevent script from using all cpu time #
 :if ( [/ip firewall address-list find where address=$tmpAddress] = "") do={ 
 :local cacheName [/ip dns cache get $i name] ;
 :log info ("added entry: $cacheName $tmpAddress");
 /ip firewall address-list add address=$tmpAddress list=blackboard-hosts; } }
#
###### Use DNS Entrys and add Address to the Firewall Address-list #
:foreach i in=[/ip dns cache all find where (name~"whatsapp") && (type="A") && (data!="240.0.0.1")] do={
 :local tmpAddress [/ip dns cache get $i address];
delay delay-time=3000ms
# prevent script from using all cpu time #
 :if ( [/ip firewall address-list find where address=$tmpAddress] = "") do={ 
 :local cacheName [/ip dns cache get $i name] ;
 :log info ("added entry: $cacheName $tmpAddress");
 /ip firewall address-list add address=$tmpAddress list=whatsapp-hosts; } }
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Script to collect IPs from the DNS cache on address lists executes just first block of code.

Sun Apr 19, 2020 12:12 am

Not sure what you need help with?
Did you create the script?
 
CBE
just joined
Topic Author
Posts: 13
Joined: Sat Apr 18, 2020 4:34 am

Re: Script to collect IPs from the DNS cache on address lists executes just first block of code.

Mon Apr 20, 2020 8:20 pm

Finally solved. I put each block of code on separate scripts and called them from a scheduler, inserting a delay between each script call. The delay made the difference.

Thanks Jotne for asking.
 
praise123
just joined
Posts: 1
Joined: Mon Feb 08, 2021 10:05 pm

Re: Script to collect IPs from the DNS cache on address lists executes just first block of code.

Mon Feb 08, 2021 10:07 pm

Please can you send me the step for which you did this? Thanks ahead. :)
Finally solved. I put each block of code on separate scripts and called them from a scheduler, inserting a delay between each script call. The delay made the difference.

Thanks Jotne for asking.
 
esantiago
just joined
Posts: 5
Joined: Wed Nov 06, 2013 9:40 pm

Re: Script to collect IPs from the DNS cache on address lists executes just first block of code.

Thu Feb 25, 2021 5:09 pm

I would like a copy of the updated script. I've been having problems prioritizing traffic for Blackboard Ultra Collaborate.
My email is esantiago@opto.inter.edu
 
elico
Member Candidate
Member Candidate
Posts: 143
Joined: Mon Nov 07, 2016 3:23 am

Re: Script to collect IPs from the DNS cache on address lists executes just first block of code.

Sun Dec 04, 2022 10:23 pm

I took only a single piece of code and it doesn't even run on V7.
It looks to me like something in the code is wrong.
:log info ("Start of script");
:foreach i in=[/ip dns cache all find where (name~"whatsapp") && (type="A") && (data!="240.0.0.1")] do={
	:log info ("Forach loop step");
	:local tmpAddress [/ip dns cache get $i address];
	:if ( [/ip firewall address-list find where address=$tmpAddress] = "") do={ 
	 :local cacheName [/ip dns cache get $i name] ;
	 :log info ("added entry: $cacheName $tmpAddress");
	/ip firewall address-list add address=$tmpAddress list=whatsapp-hosts; 
	} on-error={
		:log info ("Error on ip firewall");
	}
}
:log info ("End of script");
 
elico
Member Candidate
Member Candidate
Posts: 143
Joined: Mon Nov 07, 2016 3:23 am

Re: Script to collect IPs from the DNS cache on address lists executes just first block of code.

Sun Dec 04, 2022 10:31 pm

OK I have seen some horrible code but the above from me was a total mistake.
The next one works for now:
/log info ("Starting whatsapp script");
:foreach i in=[/ip dns cache all find where (name~"whatsapp")] do={
    :local tmpAddress [/ip dns cache get $i name];
    
    :if ( [/ip firewall address-list find where address=$tmpAddress] = "") do={ 
        :local cacheName [/ip dns cache get $i name] ;
        /log info ("added entry: $cacheName $tmpAddress");
        /ip firewall address-list add address=$tmpAddress list=whatsapp-hosts; 
    }
}
/log info ("Ending whatsapp script");

Who is online

Users browsing this forum: No registered users and 23 guests