I am already waiting for the tftp, so I have been practicing. Here is the script for the source MT box:
EDIT: This is an array - to - CSV file converter.
:global ipadd [/ip address find interface=wlan1]
:global ipaddlist ""
:foreach i in=$ipadd do={
:local ipstr [/ip address get $i address]
:if ( [:len $ipaddlist] = 0) do={
:set ipaddlist ([:toarray $ipstr])
} else={
:set ipaddlist ($ipaddlist + [:toarray $ipstr])
}
}
{ /file print file=ipaddlist count-only }
{ /file set ipaddlist.txt contents=$ipaddlist }
Move the file ipaddlist.txt from the source MT box to the target MT box
Here is the code on the second MT box:
EDIT: This is a CSV file - to array converter.
:global ipadd2 ""
:global ipaddlist2 ""
:local curpos 0
:local newpos 0
:local filearray [/file find name=ipaddlist.txt]
:if ([:len $filearray] > 0) do={
:set ipaddlist2 [/file get $filearray contents]
} else={
:log info "file ipaddlist.txt does not exist"
}
:if ([:len $ipaddlist2] > 0) do={
:set newpos [:find $ipaddlist2 "," $curpos]
:while ($newpos > 0) do={
:if ([:len $ipadd2] = 0) do={
:set ipadd2 ([:toarray [:pick $ipaddlist2 $curpos $newpos]])
} else={
:set ipadd2 ($ipadd2 + [:toarray [:pick $ipaddlist2 $curpos $newpos]])
}
:set curpos ($newpos + 1)
:set newpos [:find $ipaddlist2 "," $curpos]
}
:if ([:len $ipadd2] = 0) do={
:set ipadd2 ([:toarray [:pick $ipaddlist2 $curpos [:len $ipaddlist2]]])
} else={
:set ipadd2 ($ipadd2 + [:toarray [:pick $ipaddlist2 $curpos [:len $ipaddlist2]]])
}
:foreach i in=$ipadd2 do={
{ /ip address add address=$i interface=wlan1 }
}
}
Before you have this set your ip addresses, I would test this for a while to insure it does what you want. Let me know if I made any errors or typos. I tested all except assigning the ip addresses to the interface.
Keeping with standards, the ipaddlist.txt file is a CSV list.
ADD: The test was putting 3 sets of ip addresses (10.0.1.1/24, 10.0.2.1/24, and 10.0.3.1/24) on ether3, then running both routines, and
:env pri
ADD: The script no longer aborts if the CSV file does not exist. It will log it.