From 327740d25592c12c17bb9b87a853cc86abc4548a Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 9 Dec 2021 20:55:15 +0100 Subject: mod/ipcalc: introduce $IPCalcReturn --- mod/ipcalc | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/mod/ipcalc b/mod/ipcalc index 64a03a9..bbb9577 100644 --- a/mod/ipcalc +++ b/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; } + -- cgit v1.2.3-54-g00ecf