Community discussions

MikroTik App
 
mabels
just joined
Topic Author
Posts: 19
Joined: Sun Feb 24, 2013 11:47 pm

What is type ip-prefix

Thu Mar 07, 2013 9:42 pm

Hello,

i would like to use the "in" function which works fine for the "lightly" documented type ip-prefix. But i have a
strings that looks like "1.2.3.4/3" how could i convert this string to a ip-prefix type so that
this will work?
/ip route> :global a "1.2.3.4/4"   
/ip route> :global b "1.2.3.4/4"  
/ip route> :put ($a in $b)
false
/ip route> :global a [/ip route get 1 dst-address]     
/ip route> :global b [/ip route get 1 dst-address]     
/ip route> :put ($a in $b)                              
true
thx in advance

meno
 
User avatar
skot
Long time Member
Long time Member
Posts: 586
Joined: Wed Nov 30, 2011 3:05 am

Re: What is type ip-prefix

Fri Mar 08, 2013 9:15 am

I'm not certain, but I think the first example you gave is not valid, so it will always be false.

Initially, I thought using :toip would work, but apparently not with the mask. The string is converted to a blank variable with a type of "nil"

ros code

:global a "192.168.0.10/32"
:global b "192.168.0.0/24"
:put "a: $[:typeof $a], b: $[:typeof $b]"
a: str, b: str
:set a [:toip $a]
:set b [:toip $b]
:put "a: $[:typeof $a], b: $[:typeof $b]"
a: nil, b: nil

Funny that if you do it this way, the variable type is "nothing":

ros code

:global a [:toip "192.168.0.10/32"]
:global b [:toip "192.168.0.0/24"]
:put "a: $[:typeof $a], b: $[:typeof $b]"
a: nothing, b: nothing

The :toip conversion works fine without the mask, but the mask is necessary for the "in" function to work:

ros code

:global a "192.168.0.10"
:global b "192.168.0.0"
:put "a: $[:typeof $a], b: $[:typeof $b]"
a: str, b: str
:set a [:toip $a]
:set b [:toip $b]
:put "a: $[:typeof $a], b: $[:typeof $b]"
a: ip, b: ip
:put ($a in $b)
false

Remove the quotes and it works normally:

ros code

:global a 192.168.0.10/32
:global b 192.168.0.0/24
:put "a: $[:typeof $a], b: $[:typeof $b]"
a: ip-prefix, b: ip-prefix
:put ($a in $b)
true
I don't need any karma... I have Ιησους Χριστος!
 
petrn
Member Candidate
Member Candidate
Posts: 179
Joined: Thu Jul 29, 2010 3:56 am

Re: What is type ip-prefix

Fri Mar 08, 2013 6:16 pm

I'm not certain, but I think the first example you gave is not valid, so it will always be false.

Initially, I thought using :toip would work, but apparently not with the mask. The string is converted to a blank variable with a type of "nil"
:toip converts string "192.168.0.10/32" to type ip-prefix and string "192.168.0.10" to type ip.

BTW you can see :globals by:

ros code

/environment print
Petr
 
User avatar
skot
Long time Member
Long time Member
Posts: 586
Joined: Wed Nov 30, 2011 3:05 am

Re: What is type ip-prefix

Fri Mar 08, 2013 7:46 pm

:toip converts string "192.168.0.10/32" to type ip-prefix and string "192.168.0.10" to type ip.
What version of RouterOS are you using? I was using 5.22 for the tests above...
I don't need any karma... I have Ιησους Χριστος!
 
petrn
Member Candidate
Member Candidate
Posts: 179
Joined: Thu Jul 29, 2010 3:56 am

Re: What is type ip-prefix

Fri Mar 08, 2013 9:35 pm

What version of RouterOS are you using? I was using 5.22 for the tests above...
Interesting - i used 5.24, and yes 5.22 behaviour is different.
Petr
 
mabels
just joined
Topic Author
Posts: 19
Joined: Sun Feb 24, 2013 11:47 pm

Re: What is type ip-prefix

Sat Mar 09, 2013 1:52 am

What version of RouterOS are you using? I was using 5.22 for the tests above...
Interesting - i used 5.24, and yes 5.22 behaviour is different.
I use 6.0rc11... but still there is no solution.

thx
 
mabels
just joined
Topic Author
Posts: 19
Joined: Sun Feb 24, 2013 11:47 pm

Re: What is type ip-prefix

Mon Mar 11, 2013 10:39 pm

:toip converts string "192.168.0.10/32" to type ip-prefix and string "192.168.0.10" to type ip.
What version of RouterOS are you using? I was using 5.22 for the tests above...
So i use 6.0rc11 and i get
[admin@mam-wl] > :put [:typeof [:toip "172.16.143.10/13"]]
nil
So why is my toip working totally different. What could be a solution of my problem.

Meno
 
sja
newbie
Posts: 29
Joined: Sun Jan 22, 2012 6:26 pm
Location: Italy

Re: What is type ip-prefix

Tue Nov 12, 2013 8:59 am

I came across this thread whilst researching a problem I had involving ip-prefix.

The following snippet works for me on v6.6.
:global a "1.2.3.4/4"
:global myproc [:parse (":global aiprefix " . $a )] 
$myproc 
:put $aiprefix
:put [:typeof  $aiprefix]
 
vitt
just joined
Posts: 1
Joined: Thu Oct 31, 2013 3:17 pm

Re: What is type ip-prefix

Tue Jul 15, 2014 2:46 am

It's stiil broken on 6.15.

You can use this workaround to convert:
:local a "192.168.1.0/24"
:local b ([[:parse ":return $a"]])
:put [:typeof $b]
ip-prefix

Who is online

Users browsing this forum: akazad and 18 guests