question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Send charcater after login

See original GitHub issue

Hello,

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:closed
  • Created 4 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Noct3commented, Sep 21, 2019

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!

0reactions
Noct3commented, Sep 21, 2019

@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.

root@VIMON0103:~# python3
Python 3.5.2 (default, Jul 10 2019, 11:58:48)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import netmiko
>>> netmiko.__file__
'/root/.local/lib/python3.5/site-packages/netmiko/__init__.py'
>>>

I edited the /root/.local/lib/python3.5/site-packages/netmiko/base_connection.py file by commenting out lines 402-405 like this:

    def _write_session_log(self, data):
        if self.session_log is not None and len(data) > 0:
            # Hide the password and secret in the session_log
            #if self.password:
                #data = data.replace(self.password, "********")
            #if self.secret:
                #data = data.replace(self.secret, "********")
            self.session_log.write(write_bytes(data, encoding=self.encoding))
            self.session_log.flush()

I still can’t see the password though:

root@VIMON0103:~# python3 test.py
_cmdline-mode on
All commands can be displayed and executed. Continue? [Y/N]
_cmdline-mode on
All commands can be displayed and executed. Continue? [Y/N]
_cmdline-mode on
All commands can be displayed and executed. Continue? [Y/N]
y
Please input password:
********
Error: Invalid password.
<VISW0102>
name TEST2
          ^
 % Unrecognized command found at '^' position.
<VISW0102>
root@VIMON0103:~# 

Any idea why it’s still doing that?

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cant login anymore after character transfer - Blizzard Forums
I have transfered 3 characters yesterday in wow classic and was able to play with all 3 characters without any problems.
Read more >
How to send characters in PuTTY serial communication only ...
To get the characters to display on the screen as you enter them, set "Local echo" to "Force on". To get the terminal...
Read more >
Character Transfer - World of Warcraft | Battle.net
Transfer characters between World of Warcraft® realms or accounts, enabling you to play with a new community of players and/or find old friends...
Read more >
Passing passwords which contain special characters on the ...
Passing passwords which contain special characters on the command line. Section: Login issues Updated: August 05, 2020 10:53.
Read more >
linux - Is there any reason why I get ^[[A when I press up arrow ...
Basically, your shell would normally intercept the keypress, but there's nothing to do that at the login prompt. So the character that you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found