Community discussions

MikroTik App
 
User1992
just joined
Topic Author
Posts: 9
Joined: Thu Aug 12, 2021 11:28 am

Change IP address and bridge all LAN ports in Paramiko script?

Thu Aug 12, 2021 12:03 pm

Hi, I am writing a paramiko script that automates the configuration of a router board. This changes the name of the router, the wifi password, the router password, IP addresses, DHCP range and then bridges all LAN ports. I can change the name of the router, the wifi password and the router password but I don't know the command for editing already existing /ip address, /ip pool, /ip dhcp client, /ip dns static etc. All I've managed to do so far is add another ip address to a different eth port and using set doesn't work to change ip addresses or the dhcp pool. Also I can't figure out the command/commands necessary for bridging all LAN ports.
Any help with this would be appreciated
 
jarda
Forum Guru
Forum Guru
Posts: 7756
Joined: Mon Oct 22, 2012 4:46 pm

Re: Change IP address and bridge all LAN ports in Paramiko script?

Thu Aug 12, 2021 1:02 pm

Changing something by a script is quite problematic. Rather make full configuration script and run it in the device with blank configuration. There is a feature that allows you to remove config and run the script right after.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Change IP address and bridge all LAN ports in Paramiko script?

Thu Aug 12, 2021 1:46 pm

Is very easy,
configure a test machine used as template,
/export file=script
and you have the script.

add
:delay 20s
on top and use it as template script used during reset configuration "run after reset" with no-default option set
 
User1992
just joined
Topic Author
Posts: 9
Joined: Thu Aug 12, 2021 11:28 am

Re: Change IP address and bridge all LAN ports in Paramiko script?

Thu Aug 12, 2021 3:55 pm

Is very easy,
configure a test machine used as template,
/export file=script
and you have the script.

add
:delay 20s
on top and use it as template script used during reset configuration "run after reset" with no-default option set
Hi, thanks for the advice. So I got the script from export, then I just add 'delay 20s' at the top of the script? If I were to then use this in a python paramiko script would I just use the command 'stdin, stdout, stderr = client.exec_command('system reset-configuration no-defaults=yes run-after-reset=flash/script.rsc')'? Also, would I need to upload the script to the flash folder on the router or could I use a local address on my computer somehow?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Change IP address and bridge all LAN ports in Paramiko script?

Thu Aug 12, 2021 4:39 pm

I'm trying to explain better,
send remotely the file, after you set identity, IPs, and other parameters wanted from template (add :delay20s on top)
then exec on remote device where the file is put:
/system reset-configuration skip-backup=no keep-users=no no-defaults=yes caps-mode=no run-after-reset=myscript.rsc
Last edited by rextended on Thu Aug 12, 2021 5:43 pm, edited 1 time in total.
 
User1992
just joined
Topic Author
Posts: 9
Joined: Thu Aug 12, 2021 11:28 am

Re: Change IP address and bridge all LAN ports in Paramiko script?

Thu Aug 12, 2021 5:26 pm

I'm trying to expalin better,
send remotely the file, after you set identity, IPs, and other parameters wanted from template (add :delay20s on top)
then exec on remote device where the file is put:
/system reset-configuration skip-backup=no keep-users=no no-defaults=yes caps-mode=no run-after-reset=myscript.rsc
That's just the one thing that I don't know how to do, how do I remotely send the template script from my computer to the flash folder or file directory of a new router so I can execute it? What is the terminal command?
 
User1992
just joined
Topic Author
Posts: 9
Joined: Thu Aug 12, 2021 11:28 am

Re: Change IP address and bridge all LAN ports in Paramiko script?

Thu Aug 12, 2021 5:35 pm

Changing something by a script is quite problematic. Rather make full configuration script and run it in the device with blank configuration. There is a feature that allows you to remove config and run the script right after.
I created a full configuration script and downloaded it to my computer from a router, now I just don't know how to upload that same script to a new router so I can execute it from a paramiko file
 
robertkjonesjr
Frequent Visitor
Frequent Visitor
Posts: 63
Joined: Tue Jul 03, 2012 1:39 am

Re: Change IP address and bridge all LAN ports in Paramiko script?

Thu Aug 12, 2021 5:44 pm

Perhaps try sftp or scp to push the script.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Change IP address and bridge all LAN ports in Paramiko script?

Thu Aug 12, 2021 5:46 pm

I'm trying to expalin better,
send remotely the file, after you set identity, IPs, and other parameters wanted from template (add :delay20s on top)
then exec on remote device where the file is put:
/system reset-configuration skip-backup=no keep-users=no no-defaults=yes caps-mode=no run-after-reset=myscript.rsc
That's just the one thing that I don't know how to do, how do I remotely send the template script from my computer to the flash folder or file directory of a new router so I can execute it? What is the terminal command?
/tool fetch url=https://ww.mywebserver.ext/thisfolder/myscript.rsc

Who is online

Users browsing this forum: No registered users and 36 guests