diff options
Diffstat (limited to 'global-functions')
-rw-r--r-- | global-functions | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/global-functions b/global-functions index c3cab0c..eaf4532 100644 --- a/global-functions +++ b/global-functions @@ -30,6 +30,7 @@ :global GetMacVendor; :global GetRandomNumber; :global GetRandomSha256; +:global IPCalc; :global LogPrintExit; :global MailServerIsUp; :global MkDir; @@ -335,6 +336,22 @@ :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 :set LogPrintExit do={ :local Severity [ :tostr $1 ]; |