M
M
MrDZ2020-04-16 18:03:06
PowerShell
MrDZ, 2020-04-16 18:03:06

Script to add address with variable?

Greetings. Task: add addresses for ip tunnel to a number of mikrotiks 192.168.1.1 192.168.2.1 and so on. The question is how to automate this? If it is known that, for example, for 192.168.1.1 - the address will be 172.0.1.1, for 192.168.2.1 - 172.0.2.1
ip address add address=172.0.1.1/32 interface=IP_tunnel network=172.0.1.1 .

I usually send commands to Mikrotik using powershell.

Maybe someone did something similar, please share the solution))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Kharchenko, 2020-04-16
@AVX

Write a powershell script for you? So it's not here, it's freelance.
Briefly: if the IP of all Mikrotiks is known in advance, and it is known what command to give for each, and they are amenable to some rule (well, as they gave in the example, one digit changes in the IP address), then everything is simple - we make a plate in excel / libreoffice , in one column the ip of the device, in the second what to write, well, if something else changes, then other parameters can be written in different columns. Export to csv file. We write a script that goes through all the lines from the file in a loop, breaks them into variables, and slips them into the command, well, it would also be nice to check the availability of the device, and log what worked correctly, what didn’t. Everything.
If there are a lot of devices, and they may not always be included, then you can also enter a parameter in the plate that shows that this device has already been processed successfully. And then the script, upon completion, will make a new csv file of the same type, and replace the original one, and at the next start it will process only those devices that have not been processed. By periodically running the script, you can eventually catch all the devices. But if they are always available, then all this is not necessary, it is enough to run it once and then check the result.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question