I am using paramiko to get information from switch. The manul step would be:
- login to the switch via ssh
- run a simple command
here is the output:
SW10 [standalone: master] > show interfaces ethernet 1/32 status
Port Operational state Speed Negotiation
---- ----------------- ----- -----------
Eth1/32 Up 10 Gbps No-Negotiation
You can see the output just text.
But when I run this via a script, I got the following strange characters.
import paramiko
import time
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('10.10.21.22', username='admin', password='pass')
channel = ssh.invoke_shell()
resp = channel.recv(9999)
show_interface_cmd = "show interfaces ethernet 1/21 status\r\n"
channel.send(show_interface_cmd)
resp = channel.recv(9999)
print(resp)
Output:
b'\rSW10 [standalone: master] > show interfaces ethernet 1/26 status\r\r\n\x1b[?1h\x1b=\r\r\nPort
Operational state Speed Negoti \x08ation \r\n----
----------------- ----- ------ \x08----- \r\nEth1/26 Up
10 Gbps No-Neg \x08otiation \r\n\r\x1b[K\x1b[?1l\x1b>\rSW10 [standalone: master] > \r\r\n\rSW10 [standalone: master] > '
Then if I send another correct command and try to get the response with recv
, the output will contains error.
My question is why I got this kind of strange output? And how to handle this in the right way? Thanks.