Dear Mikrotik-lovers,
is there any code snippet available, which gets the prefix from an IPv6 address?
Not simply searching for “::/”. It should be able to handle situations like:
fd00::9/64
2a02:9841:100::9/64
2a02:9141:100:88::9/64
2a02:8753:0400:0000:1d24:425d:993b:74ed/64
Something which handles the bits of the netmask would be nice as well.
Maybe something like this:
:local GetPrefix do={
:return [[:parse ":return $1"]];
}
:put [$GetPrefix "fd00::9/64"];
:put [$GetPrefix "2a02:9841:100::9/64"];
:put [$GetPrefix "2a02:9141:100:88::9/64"];
:put [$GetPrefix "2a02:8753:0400:0000:1d24:425d:993b:74ed/64"];
:put [$GetPrefix "2a02:8753:0400:0000:1d24:425d:993b:74ed/80"];
:put [$GetPrefix "2a02:8753:0400:0000:1d24:425d:993b:74ed/24"];
Output:
fd00::/64
2a02:9841:100::/64
2a02:9141:100:88::/64
2a02:8753:400::/64
2a02:8753:400:0:1d24::/80
2a02:8700::/24
As you can see, the prefix length is also correctly handled.
That’s perfect. Thank you very much, CGGXANNX!