Send charcater after login
See original GitHub issueHello,
First of all, I am by no mean a python expert. This literally my first attemp at a script using netmiko.
I am trying to write a script that will connect to HP switches that are more oriented towards SMBs. They are HP 1910 (JE009A). I believe these came from the 3Com acquisiton.
I can SSH into the switch and enter the “command line” mode but I am then prompted to answer “Y” or “N”. Here what it looks like:
root@VIMON0103:~# ssh admin@192.168.0.241
admin@192.168.0.241's password:
<SW0102> _cmdline-mode on
_All commands can be displayed and executed. Continue? [Y/N]_ y
Please input password:******
_Warning: Now you enter an all-command mode for developer's testing, some commands may affect operation by wrong use, please carefully use it with our engineer's direction._
<SW0102> system-view
_System View: return to User View with Ctrl+Z._
[SW0102]
Basically, I need to be able to initate the connection, enter the “_cmdline_mode on” command, answer “y” and then enter the password.
I am trying with the following script:
from netmiko import ConnectHandler
visw0102 = {
'device_type': 'hp_comware',
'ip': '192.168.0.241',
'username': 'admin',
'password': 'password',
}
net_connect = ConnectHandler(**visw0102)
output = net_connect.send_command('_cmdline-mode on')
print (output)
if 'continue' in output:
output += net_connect.send_command_timing('y')
print (output)
output = net_connect.send_command('512900')
print (output)
Note: 512900 is the default password to enter “command line” mode
Then the script stops right there. It’s like the ‘y’ character is not sent correctly or that it’s not interpreted as the answer to the question.
Here’s the output of the script:
root@VIMON0103:~# python3 test.py
All commands can be displayed and executed. Continue? [Y/N]
All commands can be displayed and executed. Continue? [Y/N]
^
% Unrecognized command found at '^' position.
Is there a way I can send the ‘y’ character in a way that it would be handled correctly?
Thanks
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (4 by maintainers)
Top GitHub Comments
I think I figured it out.
The
if
statement is case sensitive. I was telling it to look for ‘continue’, but the actual prompt had a capital ‘C’ so it was skipping over it.All commands can be displayed and executed. Continue? [Y/N]
Once I figured that out, the rest of the script ran successfully. It’s always the little things I guess.
Thank you very much for you help @ktbyers and @carlmontanari!
@carlmontanari Thanks Carl. I was able to confirm that I was editing the right file.
I did try commenting out these lines but the password still gets replaced.
I edited the
/root/.local/lib/python3.5/site-packages/netmiko/base_connection.py
file by commenting out lines 402-405 like this:I still can’t see the password though:
Any idea why it’s still doing that?
Thanks!