Community discussions

MikroTik App
 
Devil
Member Candidate
Member Candidate
Topic Author
Posts: 170
Joined: Thu Jul 21, 2011 9:13 am

How to convert a string to ip-prefix data type?

Thu Feb 12, 2015 7:49 am

Lets create a dynamic address list entry first:
/ip firewall address-list add list=test_list comment=test_comment dynamic=yes address=10.0.0.0/8
Now, any one has any idea why do i get false response when i issue:
:put (10.0.0.1 in [/ip firewall address-list get [find comment=test_comment] address])
when at the very time, issuing
:put (10.0.0.1 in 10.0.0.0/8)
would give me true ?
Also, using :toip , did not make any difference
unless i'm missing something, this seems like a bug to me

Edit: Upon further investigation, i believe the problem is that "/ip firewall address-list get .." , gives back a string data type while the 'in' operator, requires either ip or ip-prefix data type. we have :toip command to convert a string to ip. but it does not work for an ip string with prefix. so the question changes to: How to convert a string to ip-prefix data type?

Update: Just contacted MikroTik and they confirmed that this is an issue and said they'll find a way to solve it.
 
A9691
newbie
Posts: 25
Joined: Sat May 14, 2016 10:58 am

Re: How to convert a string to ip-prefix data type?

Fri Jul 01, 2016 3:16 pm

If $ipp is a string containing an ip-prefix then [[:parse ":return ".$ipp]] returns that ip-prefix.

A function that does that conversion:
:global toipprefix do={:local result [[:parse ":return $1"]]; :return $result} 
[$toipprefix "192.168.2.100/24"] will evaluate to ip-prefix 192.168.2.100/24
 
Devil
Member Candidate
Member Candidate
Topic Author
Posts: 170
Joined: Thu Jul 21, 2011 9:13 am

Re: How to convert a string to ip-prefix data type?

Fri Jul 01, 2016 5:58 pm

That's a pretty clever solution. well done
 
Devil
Member Candidate
Member Candidate
Topic Author
Posts: 170
Joined: Thu Jul 21, 2011 9:13 am

Re: How to convert a string to ip-prefix data type?

Sat Jul 16, 2016 5:18 am

I finally had the time to try this myself. How the hell did you come up with that? this is genius. I'm not even entirely sure why it works. and furthermore, why only when the parse command is enclosed with an extra '[ ]' pair. You deserve a reputation point for this. unfortunately though, i don't seem to be able to give any.
Thanks for taking the time to find this topic and respond to it.

Who is online

Users browsing this forum: No registered users and 38 guests