mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2024-05-11 05:55:19 +00:00
global-functions: add $IPCalc
[admin@MikroTik] > $IPCalc 192.168.88.188/20 Address: 192.168.88.188 Netmask: 255.255.240.0 Network: 192.168.80.0/20 HostMin: 192.168.80.1 HostMax: 192.168.95.254 Broadcast: 192.168.95.255
This commit is contained in:
@ -30,6 +30,7 @@
|
|||||||
:global GetMacVendor;
|
:global GetMacVendor;
|
||||||
:global GetRandomNumber;
|
:global GetRandomNumber;
|
||||||
:global GetRandomSha256;
|
:global GetRandomSha256;
|
||||||
|
:global IPCalc;
|
||||||
:global LogPrintExit;
|
:global LogPrintExit;
|
||||||
:global MailServerIsUp;
|
:global MailServerIsUp;
|
||||||
:global MkDir;
|
:global MkDir;
|
||||||
@ -335,6 +336,22 @@
|
|||||||
:return $FingerPrint;
|
:return $FingerPrint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# calculate and print netmask, network, min host, max host and broadcast
|
||||||
|
:set IPCalc do={
|
||||||
|
:local Input [ :tostr $1 ];
|
||||||
|
: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);
|
||||||
|
|
||||||
|
:put ( \
|
||||||
|
"Address: " . $Address . "\n\r" . \
|
||||||
|
"Netmask: " . $Mask . "\n\r" . \
|
||||||
|
"Network: " . ($Address & $Mask) . "/" . $Bits . "\n\r" . \
|
||||||
|
"HostMin: " . (($Address & $Mask) | 0.0.0.1) . "\n\r" . \
|
||||||
|
"HostMax: " . (($Address | ~$Mask) ^ 0.0.0.1) . "\n\r" . \
|
||||||
|
"Broadcast: " . ($Address | ~$Mask));
|
||||||
|
}
|
||||||
|
|
||||||
# log and print with same text, optionally exit
|
# log and print with same text, optionally exit
|
||||||
:set LogPrintExit do={
|
:set LogPrintExit do={
|
||||||
:local Severity [ :tostr $1 ];
|
:local Severity [ :tostr $1 ];
|
||||||
|
Reference in New Issue
Block a user