I need assistance with this project and issues im having.
I am able to make changes to this juniper router with no issues.. The issue comes in when I need to change the password for a user.
Per the screen or the output below... I have attempted: user sends the command to change the password. Then it's suppose to get prompted with the New Password from the CLI which I'm attempting to enter it with the passwd1 and 2 string to be sent over per below. I even attempted to hid the output with getpass() but nothing.. it idles then since is unable to enter the password then it gets skipped and goes to the expect:
There is another way of implimenting it:
from passlib.hash import md5_crypt
from getpass import getpass
user = getpass()
p1 = getpass()
hashpwd = md5_crypt.encrypt(p1)
commands = 'set system login user '+user+' class read-only authentication encrypted-password '+hashpwd
print (commands)
Output:
Password:
Password:
set system login user Vijay class read-only authentication encrypted-password $1$siC6W8.B$8FeEjf/Nt7shR1e8Axl.v1
For handling Junos devices using python, I would recommend you to use PyEZ - https://github.com/Juniper/py-junos-eznc
Example:
from jnpr.junos import Device
from lxml import etree
dev = Device('hostname', user='username', password='Password123')
dev.open()
cnf = dev.rpc.get_config() # similar to 'show configuration | no-more' on cli
print (etree.tounicode(cnf))
dev.close()