mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2025-12-06 09:59:28 +00:00
Merge branch 'netmask4' into next
This commit is contained in:
commit
c62f236251
3 changed files with 21 additions and 3 deletions
|
|
@ -22,10 +22,12 @@
|
|||
:global EitherOr;
|
||||
:global FetchHuge;
|
||||
:global HumanReadableNum;
|
||||
:global IfThenElse;
|
||||
:global LogPrint;
|
||||
:global LogPrintOnce;
|
||||
:global LogPrintVerbose;
|
||||
:global MIN;
|
||||
:global NetMask4;
|
||||
:global ScriptLock;
|
||||
:global WaitFullyConnected;
|
||||
|
||||
|
|
@ -114,8 +116,13 @@
|
|||
:do {
|
||||
:local Branch;
|
||||
:if ($Address ~ "^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}(/[0-9]{1,2})?\$") do={
|
||||
:if ($Address ~ "/32\$") do={
|
||||
:set Address [ :pick $Address 0 ([ :len $Address ] - 3) ];
|
||||
:local Net $Address;
|
||||
:local CIDR 32;
|
||||
:local Slash [ :find $Address "/" ];
|
||||
:if ([ :typeof $Slash ] = "num") do={
|
||||
:set Net [ :toip [ :pick $Address 0 $Slash ] ]
|
||||
:set CIDR [ :pick $Address ($Slash + 1) [ :len $Address ] ];
|
||||
:set Address [ :tostr (([ :toip $Net ] & [ $NetMask4 $CIDR ]) . [ $IfThenElse ($CIDR < 32) ("/" . $CIDR) ]) ];
|
||||
}
|
||||
:set Branch [ $GetBranch $Address ];
|
||||
:set ($IPv4Addresses->$Branch->$Address) $TimeOut;
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@
|
|||
:global MAX;
|
||||
:global MIN;
|
||||
:global MkDir;
|
||||
:global NetMask4;
|
||||
:global NotificationFunctions;
|
||||
:global ParseDate;
|
||||
:global ParseKeyValueStore;
|
||||
|
|
@ -990,6 +991,13 @@
|
|||
:return true;
|
||||
}
|
||||
|
||||
# return an IPv4 netmask for CIDR
|
||||
:set NetMask4 do={
|
||||
:local CIDR [ :tonum $1 ];
|
||||
|
||||
:return ((255.255.255.255 << (32 - $CIDR)) & 255.255.255.255);
|
||||
}
|
||||
|
||||
# prepare NotificationFunctions array
|
||||
:if ([ :typeof $NotificationFunctions ] != "array") do={
|
||||
:set NotificationFunctions ({});
|
||||
|
|
|
|||
|
|
@ -34,9 +34,12 @@
|
|||
# calculate and return netmask, network, min host, max host and broadcast
|
||||
:set IPCalcReturn do={
|
||||
:local Input [ :tostr $1 ];
|
||||
|
||||
:global NetMask4;
|
||||
|
||||
:local Address [ :toip [ :pick $Input 0 [ :find $Input "/" ] ] ];
|
||||
:local Bits [ :tonum [ :pick $Input ([ :find $Input "/" ] + 1) [ :len $Input ] ] ];
|
||||
:local Mask ((255.255.255.255 << (32 - $Bits)) & 255.255.255.255);
|
||||
:local Mask [ $NetMask4 $Bits ];
|
||||
|
||||
:local Return {
|
||||
"address"=$Address;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue