我在Windows中使用pexpect
进行SSH。没用因此,我安装了paramiko
。使用paramiko
可以登录到远程主机。但是我无法在'conf'命令之后运行命令。当我运行命令“ set management cwmp enable on”时,会引发错误:
无法识别的命令。
在putty
上运行时,它将类似于:
name:xyz
pass:xyz
>satus
#writes status
>magic
>UNLOCKED>
>UNLOCKED>conf
>>set management cwmp enable on
>>save
*configuration saved*
Python代码:
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect( '192.168.2.254',port = 22, username = 'xyz', password = 'xyz')
stdin, stdout, stderr = ssh.exec_command( 'status' )
output = stdout.readlines()
print "\n".join(output)
stdin, stdout, stderr = ssh.exec_command('magic')
output1 = stdout.readlines()
print output1
stdin, stdout, stderr = ssh.exec_command('conf')
output1 = stdout.readlines()
print output1
stdin, stdout, stderr = ssh.exec_command('set management cwmp enable on')
output1 = stdout.readlines()
print output1
输出:
#after executing conf command