-1

friends, does anyone know why this code runs perfectly with cisco's router but with huawei router, it stays put and doesn't finish ?

import paramiko

ssh_RT = paramiko.SSHClient()
ssh_RT.set_missing_host_key_policy(paramiko.AutoAddPolicy())

ssh_RT.connect(
    sIP,
    port=22,
    username=uuu,
    password=sss,
    timeout=5,
    look_for_keys=False,
    allow_agent=False
)

sComando = 'dis ip int br'
# sComando = 'sh ip int br'

stdin, stdout, stderr = ssh_RT.exec_command(sComando)
sOut = stdout.read().decode()
print (sOut)
ssh_RT.close()

1 Answers1

0

It worked. Like this:

def receive_data(pLenght, pTimeout):
    for x in range(pTimeout):    
        time.sleep(1)
        r = channel.recv(2024)
        z = r.decode('utf-8','ignore')
        if len(z) > pLenght:
            break
    return z


channel = ssh_RT.invoke_shell()
channel.send('dis ip int br\n')
out = receive_data(50,5)
  • For some reason, exec_command does not work for Huawei router. – Daniel Cancelier Aug 31 '20 at 16:02
  • I suspected that. That's why I asked you if you can do `ssh uuu@sss dis ip int br` on command-line. That is an equivalent of `exec_command`. – Martin Prikryl Aug 31 '20 at 18:37
  • Really ... you are right. The ssh command as you represented (on a command line) is crashing ... – Daniel Cancelier Aug 31 '20 at 21:00
  • @MartinPrikryl Just one last question about using invoke_shell and not exec_command: I saw in the other post that you didn't recommend using invoke_shell. Is the alert because invoke_shell needs more control in the code to close the channel? – Daniel Cancelier Aug 31 '20 at 21:09