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”
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..."}
thank you sir
working well
you welcome ![]()