Community discussions

 
vahid023
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 62
Joined: Mon Sep 13, 2010 1:14 pm

script for find similar domains in dns cache

Sun Sep 02, 2018 2:40 am

hi all
i am using this script to collect instagram.com ip addresses in dns cache ( for block or separate route )
but it is working only for instagram.com , now i want to work for any domains that contain cdninstagram.com ( scontent-ams3-1.cdninstagram.com)
please help me


:local hosts {"instagram.com"}
:foreach k,v in=$hosts do={
:log info "Doing $v"
:local listname $v
:resolve $v
:local iscname [/ip dns cache all find where name=$v and type="CNAME"]
:if ($iscname != "") do={
:local newname [/ip dns cache all get $iscname data]
:log info "$v is CNAME to $newname"
:set v $newname
}
:resolve $v
:foreach i in=[/ip dns cache all find where name=$v and type="A"] do={
:local ipaddr [/ip dns cache all get $i data]
/ip firewall address-list add list=$listname address=$ipaddr comment=$v
:log info "IP address: $ipaddr"
}
/ipv6 firewall address-list remove [/ipv6 firewall address-list find where list=$listname]
:foreach i in=[/ip dns cache all find where name=$v and type="AAAA"] do={
:local ipaddr [/ip dns cache all get $i data]
/ipv6 firewall address-list add list=$listname address=$ipaddr comment=$v
:log info "IPv6 address: $ipaddr"
}
}
:log info "end"
 
User avatar
ADahi
Member Candidate
Member Candidate
Posts: 217
Joined: Thu Sep 21, 2017 7:16 pm
Location: Iraq, Ninavah
Contact:

Re: script for find similar domains in dns cache

Sun Sep 02, 2018 11:41 am

you welcome
simple, easy and efficient
:do {
:local LIST "instagram";
:local DOMAIN "instagram.com";
 :foreach Crec in=[/ip dns cache all find where ( ( (type="A") || (type="CNAME") ) && (static=no) && (name~$DOMAIN) )] do={
  :local Cname [/ip dns cache get number=$Crec name]; 
  :local Cdata "";  
  :delay 1000ms;
  :if ([/ip dns cache all get $Crec type]="CNAME") do={ 
   :set $Cdata [:resolve $Cname]; } else={ 
   :set $Cdata [/ip dns cache get number=$Crec address]; } 
  :do {/ip firewall address-list
   :do {add list=$LIST address=$Cdata comment=$Cname disabled=no} on-error={:log warning message="address entry exist: List=$LIST , Host=$Cname , Address=$Cdata";}
  }
 } 
} on-error={:log error message="script failed..."}
 
vahid023
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 62
Joined: Mon Sep 13, 2010 1:14 pm

Re: script for find similar domains in dns cache

Sun Sep 02, 2018 11:09 pm

thank you sir
working well
 
User avatar
ADahi
Member Candidate
Member Candidate
Posts: 217
Joined: Thu Sep 21, 2017 7:16 pm
Location: Iraq, Ninavah
Contact:

Re: script for find similar domains in dns cache

Mon Sep 03, 2018 11:09 am

thank you sir
working well
you welcome :wink:

Who is online

Users browsing this forum: No registered users and 17 guests