How to extract network variables?

In Linux, utilizing the commands “ipcalc” or “sipcalc” followed by an IP address and subnet mask allows me to extract helpful variables using “awk”.

On RouterOS, I aim to assign the variable “10.0.88.0/24” to “network” and create variables for the minimum and maximum usable hosts, as well as the network address with a value “n” added to it.

As of now, I only know how to extract the network address by removing the subnet mask using the command: “:put [:pick $network 0 [:find $network “/”]]”

Is there a pre-existing script that accomplishes these tasks?

Some of my “tools”
http://forum.mikrotik.com/t/rextended-fragments-of-snippets/151033/1

For example for 10.31.42.56/16 (no matter the “.0.0” at the end)

{
:local source    10.31.42.56/16

:local ip        [:toip [:pick $source 0 [:find $source "/"]]]
:local prefix    [:tonum [:pick $source ([:find $source "/"] + 1) [:len $source]]]
:local submask   (255.255.255.255<<(32 - $prefix))
:local addrspace (~$submask)
:local totip     ([:tonum $addrspace] + 1)
:local network   ($ip & $submask)
:local broadcast ($ip | $addrspace)
:local first     (($network + 1) - ($prefix / 31))
:local last      (($broadcast - 1) + ($prefix / 31))
:local usable    (($last - $network) + ($prefix / 31))
:put "       Source: $source"
:put "           IP: $ip"
:put "Subnet Prefix: $prefix"
:put "  Subnet Mask: $submask"
:put "Address Space: $addrspace"
:put "    Total IPs: $totip"
:put "  Network* IP: $network"
:put "Broadcast* IP: $broadcast"
:put "    First* IP: $first"
:put "     Last* IP: $last"
:put "  Usable* IPs: $usable"
}

Source: 10.31.42.56/16
IP: 10.31.42.56
Subnet Prefix: 16
Subnet Mask: 255.255.0.0
Address Space: 0.0.255.255
Total IPs: 65536
Network* IP: 10.31.0.0
Broadcast* IP: 10.31.255.255
First* IP: 10.31.0.1
Last* IP: 10.31.255.254
Usable* IPs: 65534

  • = Network / Broadcast / First IP and Last IP are valid only when the IP are distribuited on local LAN,
    instead for routing only, all IP can be used.
    .0 and .255 are perfectly valid IP if are not the network ip or the broadcast address,
    but for compatibility with some end devices that have problems with .0 and .255 outside a /24, is better remove all .0 and all .255 from the IP pools assigned from DHCP Server.

And for 10.0.88.0/24
Source: 10.0.88.0/24
IP: 10.0.88.0
Subnet Prefix: 24
Subnet Mask: 255.255.255.0
Address Space: 0.0.0.255
Total IPs: 256
Network* IP: 10.0.88.0
Broadcast* IP: 10.0.88.255
First* IP: 10.0.88.1
Last* IP: 10.0.88.254
Usable* IPs: 254

I am not aware of any pre-existing script that accomplishes these specific tasks. However, you can use RouterOS scripting language to achieve this. Here is an example script that extracts the minimum and maximum usable hosts, as well as the network address with a value "n" added to it:

Assign the network and subnet mask

:local network "10.0.88.0/24"

Extract the network address

:local network_address [:pick $network 0 [:find $network "/"]]

Calculate the subnet mask

:local subnet_mask [:pick $network ([:find $network "/"] + 1) 2]

Calculate the number of available hosts

:local available_hosts (2 ** (32 - $subnet_mask)) - 2

Calculate the minimum usable host

:local min_host [:toip [:tonum $network_address] + 1]

Calculate the maximum usable host

:local max_host [:toip [:tonum $network_address + $available_hosts] - 1]

Calculate the network address with a value "n" added to it

:local network_n_address [:toip [:tonum $network_address + $n]]

Print the results

:put ("Network: " . $network)
:put ("Minimum usable host: " . $min_host)
:put ("Maximum usable host: " . $max_host)
:put ("Network address with n added: " . $network_n_address)

You can modify this script to suit your specific needs.

So before answering, you don’t read other people’s posts…

Is the trademark of ChatGPT invent instructions that do no exist…

Do you know where you have to put that thing’s answers?