Script to chenge netmask

Dear Colleagues,
I need help on a script. I want to change the IP netmask in multiples RoS, xxx.xxx.xxx.xxx/20 to xxx.xxx.xxx.xxx./19

How can createa code for this result? Any idea ?

Thank you.

let me try

:global ipaddress 200.220.4.254/24
:global funcN do={return [pick $ipaddress 0 [find $ipaddress "/"]]}
:global fcomb do={return ([$funcN] . $1)}

to test output

put [$fcomb /22]

to change your choice of interface

add address=[$fcomb /25] interface=ether1

things to remember, in my own understanding

  • concatenation of string uses () <-curve brackets
  • processing of certain values/perform action uses <-angular brackets
  • when using function definition, make use of “RETURN” otherwise result to
    ;200.220.4.254/25
    semicolon present, giving error

i took one example from the link, and made some change
http://wiki.mikrotik.com/wiki/Manual:Scripting-examples#See_also

hope this helps,
filumena

Thanks Filumena

Your contribution was very helpful , could finally achieve my goal with the script I Annex to share with the forum community . Already tested and works 100 %.

I hope it is useful to another that requires it.


:global ipact “/20”
:global enip
:foreach oldip in=[/ip address find where address ~“/19”] do={
:set enip [:pick [/ip address get $oldip address] /]
/ip address set $oldip address=($ipact.$enip)
}


This script searches all IP interfaces assigned to that end with the netmask / 20 and changes the network mask / 19

Best regards

Vozglobal