Is it possible to reset the admin password via API ?
We’ve got almost 200 routers out there that need some scripting done, and while I’m at it I’d like to reset the admin password too…
I googled a bit and couldn’t find an example - if someone wouldn’t mind sending me an example or two that’d be awesome.
Thanks,
Rick Smith, Network Engineer
rsmith@navitend.com | www.navitend.com
P (973) 448 0070 | F (973) 448 0264
23 US Highway 206 Byram Twp. NJ 07874
Yes that’s possible, here is an example with the Python API
#!/usr/bin/python3
import routeros_api
import sys
login_username = 'myuser'
login_password = '123123'
change_username = 'admin'
change_password = '345345'
connection = routeros_api.RouterOsApiPool('127.0.0.2', username=login_username, password=login_password)
api = connection.get_api()
api_user = api.get_resource('/user')
user = api_user.get(name=change_username)
if user:
api_user.set(id=user[0]['id'], password=change_password)
else:
print("Warning, user %s does not exist" % change_username)
sys.exit(1)
-davidc