diff options
author | Christian Hesse <mail@eworm.de> | 2021-12-09 20:55:15 +0100 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2021-12-09 20:55:15 +0100 |
commit | 327740d25592c12c17bb9b87a853cc86abc4548a (patch) | |
tree | 1ae8b8055f30a10d27fa4373f5c29107f01b93ed /mod/ipcalc | |
parent | 004621a327948526d3fffd4de0db1d722d68a172 (diff) |
mod/ipcalc: introduce $IPCalcReturn
Diffstat (limited to 'mod/ipcalc')
-rw-r--r-- | mod/ipcalc | 29 |
1 files changed, 20 insertions, 9 deletions
@@ -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; } + |