mirror of
https://git.eworm.de/cgit/routeros-scripts
synced 2025-06-27 20:08:54 +02:00
mod/ipcalc: introduce $IPCalcReturn
This commit is contained in:
parent
004621a327
commit
327740d255
1 changed files with 20 additions and 9 deletions
29
mod/ipcalc
29
mod/ipcalc
|
@ -4,10 +4,28 @@
|
|||
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
|
||||
|
||||
:global IPCalc;
|
||||
:global IPCalcReturn;
|
||||
|
||||
# calculate and print netmask, network, min host, max host and broadcast
|
||||
# print netmask, network, min host, max host and broadcast
|
||||
:set IPCalc do={
|
||||
:local Input [ :tostr $1 ];
|
||||
|
||||
:global IPCalcReturn;
|
||||
|
||||
:local Values [ $IPCalcReturn $1 ];
|
||||
|
||||
:put ( \
|
||||
"Address: " . $Values->"address" . "\n\r" . \
|
||||
"Netmask: " . $Values->"netmask" . "\n\r" . \
|
||||
"Network: " . $Values->"network" . "\n\r" . \
|
||||
"HostMin: " . $Values->"hostmin" . "\n\r" . \
|
||||
"HostMax: " . $Values->"hostmax" . "\n\r" . \
|
||||
"Broadcast: " . $Values->"broadcast");
|
||||
}
|
||||
|
||||
# calculate and return netmask, network, min host, max host and broadcast
|
||||
:set IPCalcReturn 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);
|
||||
|
@ -23,13 +41,6 @@
|
|||
"broadcast"=($Address | ~$Mask);
|
||||
}
|
||||
|
||||
:put ( \
|
||||
"Address: " . $Return->"address" . "\n\r" . \
|
||||
"Netmask: " . $Return->"netmask" . "\n\r" . \
|
||||
"Network: " . $Return->"network" . "\n\r" . \
|
||||
"HostMin: " . $Return->"hostmin" . "\n\r" . \
|
||||
"HostMax: " . $Return->"hostmax" . "\n\r" . \
|
||||
"Broadcast: " . $Return->"broadcast");
|
||||
|
||||
:return $Return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue