Community discussions

MikroTik App
 
gowthamprt
just joined
Topic Author
Posts: 3
Joined: Mon Aug 07, 2023 6:14 pm

Request for Python Script to Change L2TP Password in MikroTik Router

Sat Mar 23, 2024 7:47 pm

Dear MikroTik Support Team,

I hope this email finds you well. We are currently exploring ways to automate the process of changing L2TP passwords in our MikroTik routers to enhance our network security measures.

To achieve this automation, we are seeking a Python script that can interact with the MikroTik RouterOS API to change the L2TP password programmatically. We understand that the RouterOS API provides functionality for managing router configurations remotely, and we believe that a Python script leveraging this API can help us achieve our goal efficiently.

Ideally, the Python script should:

Connect to the MikroTik router using the RouterOS API.
Authenticate with the router using appropriate credentials.
Execute commands to change the L2TP password securely.
We would greatly appreciate it if you could provide us with a sample Python script or code snippet that demonstrates how to accomplish this task using the MikroTik RouterOS API.

Additionally, any documentation or resources related to the RouterOS API that could assist us in understanding its capabilities and usage would be highly beneficial.

Thank you very much for your assistance in this matter. We look forward to hearing from you soon.
 
mada3k
Long time Member
Long time Member
Posts: 698
Joined: Mon Jul 13, 2015 10:53 am
Location: Sweden

Re: Request for Python Script to Change L2TP Password in MikroTik Router

Sun Mar 24, 2024 10:32 am

This should be under Scripting.

Personally I would use the REST-API if possible. Then just use Python with requests module.

Second choice is just to use "ssh" in conjuction with "print terse"
 
gowthamprt
just joined
Topic Author
Posts: 3
Joined: Mon Aug 07, 2023 6:14 pm

Re: Request for Python Script to Change L2TP Password in MikroTik Router

Sun Mar 24, 2024 1:15 pm

This should be under Scripting.

Personally I would use the REST-API if possible. Then just use Python with requests module.

Second choice is just to use "ssh" in conjuction with "print terse"
[/thank you so much ]
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3505
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Request for Python Script to Change L2TP Password in MikroTik Router

Sun Mar 24, 2024 2:45 pm

Personally I would use the REST-API if possible. Then just use Python with requests module.
For background, Mikrotik has several "APIs". The low-level one is what typically called "API", and there is a python module wrappers:
https://help.mikrotik.com/docs/display/ ... mpleclient
This is more useful is were building a UI or for a "long poll" to continuously fetch data from RouterOS. But it's a lot of plumbing code to setup just for something like a password change.

So @mada3k is right using "REST API", which uses normally HTTP(S) on port 80/443, is likely easier for something like changing password:
https://help.mikrotik.com/docs/display/ROS/REST+API
The REST API mimic the CLI, and Python libraries like "requests" (or similar python HTTP client module) can call it like any other web service.

Often it's easier to start with the RouterOS CLI that you know it does what you want FIRST. Then... use the CLI command as the guide what the specific REST API call should be – since it largely putting the CLI parameters into JSON for change into body with the URL being /rest + CLI command.
 
kevinds
Long time Member
Long time Member
Posts: 651
Joined: Wed Jan 14, 2015 8:41 am

Re: Request for Python Script to Change L2TP Password in MikroTik Router

Thu Mar 28, 2024 9:58 am

I hope this email finds you well. We are currently exploring ways to automate the process of changing L2TP passwords in our MikroTik routers to enhance our network security measures.
Why not setup RADIUS? Multiple accounts can be changed without touching RouterOS.

My second choice would be SSH, connect with a key instead of a password and change the password in /ppp/secrets.
 
gowthamprt
just joined
Topic Author
Posts: 3
Joined: Mon Aug 07, 2023 6:14 pm

Re: Request for Python Script to Change L2TP Password in MikroTik Router

Sun Mar 31, 2024 2:30 pm

Can somone share python scripts for mikrotik router
 
optio
Long time Member
Long time Member
Posts: 675
Joined: Mon Dec 26, 2022 2:57 pm

Re: Request for Python Script to Change L2TP Password in MikroTik Router

Sun Mar 31, 2024 3:36 pm

For ROS API (not REST) you have Python3 example on MT help page or use pip packages like this or this.
For REST API, it should work with any HTTP client (like requests module mentioned above), requests and responses bodies are in JSON format. For eg. here is some Python module which is using REST API with requests module using JSON<->Python object (de)serialization.

Who is online

Users browsing this forum: No registered users and 4 guests