Jump to content

Hi guys, hope you all doin well 🙂

 

well i have a problem with my script on mikrotik router, the meaning of script is to go Web page copy the body of the web ( which contains only ip addresses ) and create .txt file in mikrotik files after that add ip addresses inside that .txt file into address list. My script did copy of the web body paste into .txt document but it can't add into address list , i figured out why because in body of that web the ip addresses is typed vertical and without commas, well i wanted to add some code on my script but it does not worked at all,



could someone help me with that? or provide a script maybe or other solution to fix this 😞

this is the code


 

:local url "webpagedotcom"
:local list "addresslist"


:if ([:len [/ip firewall address-list find list=$list]] = 0) do={
  /ip firewall address-list add list=$list
}


/tool fetch url=$url mode=http dst-path=ip-list.txt
:local ips [/file get ip-list.txt contents]
:local iparray [:toarray [:resolve $ips]]
:local ipregex "([0-9]{1,3}.){3}[0-9]{1,3}"
:local ipstring ""


:foreach ip in=$iparray do={
  :if ([$ip] ~ $ipregex) do={
    :set ipstring "$ipstring$ip,"
  }
}
:if ($ipstring != "") do={
  :set ipstring [:pick $ipstring 0 ([:len $ipstring]-1)]
}


:if ($ipstring != "") do={
  /ip firewall address-list set [find list=$list] address=$ipstring
}

/file remove ip-list.txt

 

ips vertical.png

Akinator V2 is here :D

Link to comment
https://linustechtips.com/topic/1499047-mikrotik-script-problem/
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×