Community discussions

MikroTik App
 
niammuddin
just joined
Topic Author
Posts: 6
Joined: Sun Aug 26, 2018 2:03 am

add ip route rules from dynamic address-list

Sun Jan 02, 2022 7:49 pm

Hello all,

I have address list with list name "geo-ip-hotstar" with domain "geoip.hotstar.com.edgekey.net"

I want to add all address from geoip.hotstar.com.edgekey.net to "ip route rules"

I have script:
:foreach i in=[/ip firewall address-list find where list=geo-ip-hotstar] do={
    :put ("/ip route rule add dst-address=" . [/ip firewall address-list get $i address] . " table=geo-ip-hotstar")
    }

output is:
/ip route rule add dst-address=geoip.hotstar.com.edgekey.net table=geo-ip-hotstar
/ip route rule add dst-address=184.28.72.72 table=geo-ip-hotstar
/ip route rule add dst-address=184.28.72.91 table=geo-ip-hotstar
/ip route rule add dst-address=184.28.72.65 table=geo-ip-hotstar
/ip route rule add dst-address=184.28.72.50 table=geo-ip-hotstar
/ip route rule add dst-address=184.28.72.83 table=geo-ip-hotstar
/ip route rule add dst-address=184.28.72.96 table=geo-ip-hotstar
/ip route rule add dst-address=184.28.72.90 table=geo-ip-hotstar
/ip route rule add dst-address=184.28.72.88 table=geo-ip-hotstar
/ip route rule add dst-address=184.28.72.97 table=geo-ip-hotstar
/ip route rule add dst-address=184.28.72.75 table=geo-ip-hotstar
/ip route rule add dst-address=184.28.72.99 table=geo-ip-hotstar
/ip route rule add dst-address=184.28.72.66 table=geo-ip-hotstar
/ip route rule add dst-address=184.28.72.64 table=geo-ip-hotstar
/ip route rule add dst-address=184.28.72.128 table=geo-ip-hotstar
/ip route rule add dst-address=184.28.72.98 table=geo-ip-hotstar
/ip route rule add dst-address=184.28.72.106 table=geo-ip-hotstar
/ip route rule add dst-address=184.28.72.138 table=geo-ip-hotstar
/ip route rule add dst-address=184.28.72.115 table=geo-ip-hotstar

how to remove first line output, in this case "geoip.hotstar.com.edgekey.net" from output my script.

and how to run this output for add to ip route rule?

sorry if my english is bad, thanks.
 
ConnyMercier
Forum Veteran
Forum Veteran
Posts: 736
Joined: Tue Dec 17, 2019 1:08 pm

Re: add ip route rules from dynamic address-list  [SOLVED]

Mon Jan 03, 2022 1:43 am

Queston 1:
how to remove first line output, in this case "geoip.hotstar.com.edgekey.net" from output my script.
Answer:
:foreach i in=[/ip firewall address-list find where list=geo-ip-hotstar] do={
	:if ([typeof [toip [/ip firewall address-list get $i address]]] = "ip") do={
		#Item is an IP-Address
		:put ("/ip route rule add dst-address=" . [/ip firewall address-list get $i address] . " table=geo-ip-hotstar")
	}
}


Question 2:
and how to run this output for add to ip route rule?
Answer
:foreach i in=[/ip firewall address-list find where list=geo-ip-hotstar] do={
	:if ([typeof [toip [/ip firewall address-list get $i address]]] = "ip") do={
		#Item is an IP-Address
		/ip route rule add dst-address=[/ip firewall address-list get $i address] table="geo-ip-hotstar"
	} else={
		#Item is not an IP-Address
	}
}
 
niammuddin
just joined
Topic Author
Posts: 6
Joined: Sun Aug 26, 2018 2:03 am

Re: add ip route rules from dynamic address-list

Mon Jan 17, 2022 7:27 am

Queston 1:
how to remove first line output, in this case "geoip.hotstar.com.edgekey.net" from output my script.
Answer:
:foreach i in=[/ip firewall address-list find where list=geo-ip-hotstar] do={
	:if ([typeof [toip [/ip firewall address-list get $i address]]] = "ip") do={
		#Item is an IP-Address
		:put ("/ip route rule add dst-address=" . [/ip firewall address-list get $i address] . " table=geo-ip-hotstar")
	}
}


Question 2:
and how to run this output for add to ip route rule?
Answer
:foreach i in=[/ip firewall address-list find where list=geo-ip-hotstar] do={
	:if ([typeof [toip [/ip firewall address-list get $i address]]] = "ip") do={
		#Item is an IP-Address
		/ip route rule add dst-address=[/ip firewall address-list get $i address] table="geo-ip-hotstar"
	} else={
		#Item is not an IP-Address
	}
}
big Thanks for your answer

Who is online

Users browsing this forum: No registered users and 13 guests