mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2025-12-06 09:59:28 +00:00
mod/ipcalc: support IPv6
Well, some of these values do not make a lot of sense for IPv6... Something to be cleaned up later.
This commit is contained in:
parent
ea05b69f7c
commit
b80b872e55
1 changed files with 17 additions and 6 deletions
|
|
@ -36,21 +36,32 @@
|
||||||
:local Input [ :tostr $1 ];
|
:local Input [ :tostr $1 ];
|
||||||
|
|
||||||
:global NetMask4;
|
:global NetMask4;
|
||||||
|
:global NetMask6;
|
||||||
|
|
||||||
:local Address [ :toip [ :pick $Input 0 [ :find $Input "/" ] ] ];
|
:local Address [ :pick $Input 0 [ :find $Input "/" ] ];
|
||||||
:local Bits [ :tonum [ :pick $Input ([ :find $Input "/" ] + 1) [ :len $Input ] ] ];
|
:local Bits [ :tonum [ :pick $Input ([ :find $Input "/" ] + 1) [ :len $Input ] ] ];
|
||||||
:local Mask [ $NetMask4 $Bits ];
|
:local Mask;
|
||||||
|
:local One;
|
||||||
|
:if ([ :typeof [ :toip $Address ] ] = "ip") do={
|
||||||
|
:set Address [ :toip $Address ];
|
||||||
|
:set Mask [ $NetMask4 $Bits ];
|
||||||
|
:set One 0.0.0.1;
|
||||||
|
} else={
|
||||||
|
:set Address [ :toip6 $Address ];
|
||||||
|
:set Mask [ $NetMask6 $Bits ];
|
||||||
|
:set One ::1;
|
||||||
|
}
|
||||||
|
|
||||||
:local Return {
|
:local Return ({
|
||||||
"address"=$Address;
|
"address"=$Address;
|
||||||
"netmask"=$Mask;
|
"netmask"=$Mask;
|
||||||
"networkaddress"=($Address & $Mask);
|
"networkaddress"=($Address & $Mask);
|
||||||
"networkbits"=$Bits;
|
"networkbits"=$Bits;
|
||||||
"network"=(($Address & $Mask) . "/" . $Bits);
|
"network"=(($Address & $Mask) . "/" . $Bits);
|
||||||
"hostmin"=(($Address & $Mask) | 0.0.0.1);
|
"hostmin"=(($Address & $Mask) | $One);
|
||||||
"hostmax"=(($Address | ~$Mask) ^ 0.0.0.1);
|
"hostmax"=(($Address | ~$Mask) ^ $One);
|
||||||
"broadcast"=($Address | ~$Mask);
|
"broadcast"=($Address | ~$Mask);
|
||||||
}
|
});
|
||||||
|
|
||||||
:return $Return;
|
:return $Return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue