Community discussions

MikroTik App
 
jeroenp
Member Candidate
Member Candidate
Topic Author
Posts: 159
Joined: Mon Mar 17, 2014 11:30 am
Location: Amsterdam
Contact:

What forms of IPv4 addresses does Mikrotik accept?

Mon Oct 31, 2016 10:08 am

http://wiki.mikrotik.com/wiki/Manual:IP/Address doesn't detail what forms of IPv4 addresses are being accepted.

For instance inet_addr accepts a much wide range of input (like leading zero for octal and many other forms) than the often used human readable quad-dotted decimal form a.b.c.d.e where a can be in the decimal range 0..255.

So: what forms of IPv4 addresses does Mikrotik support in both the UI and scripts?

--jeroen
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 6111
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: What forms of IPv4 addresses does Mikrotik accept?

Mon Oct 31, 2016 11:54 am

It accepts human readable 4 decimal octets.
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2411
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: What forms of IPv4 addresses does Mikrotik accept?

Mon Oct 31, 2016 12:00 pm

Some playing around from a terminal tells me that all of those are allowed indeed, and behave as described in inet_addr(3).
[admin@MikroTik] > :local val 0.32.16.8;:put $val;:put [:typeof $val];        
0.32.16.8
ip
[admin@MikroTik] > :local val 32.16.8;:put $val;:put [:typeof $val];  
32.16.0.8
ip
[admin@MikroTik] > :local val 0.16.8;:put $val;:put [:typeof $val];  
0.16.0.8
ip
[admin@MikroTik] > :local val 16.8;:put $val;:put [:typeof $val];  
16.0.0.8
ip
[admin@MikroTik] > :local val 0.8;:put $val;:put [:typeof $val];  
0.0.0.8
ip
The edge case is an IP with a single octet... You can't really do that, as it is treated as a value of type "num" (which, in RouterOS is actually an integer, not a float, as "num" might have you believe). You can only use "0.<octet>" as in the example above.

Some further tests also show that (as expected), only decimal notation is allowed. No octal or, as the example on the man page suggests, hex. Hex is outright invalid unless in the "\<hex>" form, within quotes that ultimately produce a string. A string you could manually cast to an IP with ":toip" if the hex forms a valid decimal notated value, but still:
[admin@MikroTik] > :local val 008.008.008.008;:put $val;:put [:typeof $val];        
008.008.008.008
str
[admin@MikroTik] > :local val 8.008.008.008;:put $val;:put [:typeof $val];  
8.008.008.008
str
[admin@MikroTik] > :local val 0.008.008.008;:put $val;:put [:typeof $val];  
0.008.008.008
str
[admin@MikroTik] > :local val 0.8.8.008;:put $val;:put [:typeof $val];    
0.8.8.008
str
[admin@MikroTik] > :local val 0.008;:put $val;:put [:typeof $val];    
00:00:00.008
time
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)

Who is online

Users browsing this forum: No registered users and 19 guests