下面的代码在连接一台 Dell iDRAC 时,会有 Oops, unhandled type 3 的报错,但连接其它服务器的BMC时正常的
>>> import paramiko
>>> client = paramiko.SSHClient()
>>> client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>>> client.connect(hostname='x.x.x.x', port=22, username='xxxx', password='xxxxx', allow_agent=False)
>>> channel = client.invoke_shell()
Oops, unhandled type 3 ('unimplemented')
Exception (client): Invalid packet blocking
后面才知道可能设备需要模拟输入认证,改成下面的就可以了, 主要是使用了 Transport 来进行模拟
[root@h92 ~]# ./python/bin/python3
Python 3.6.8 (default, Nov 16 2020, 16:55:22)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
>>> import paramiko
>>> client = paramiko.SSHClient()
>>> client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>>> transport = paramiko.Transport(('x.x.x.x', 22))
>>> transport.connect(username='xxxx')
>>> transport.auth_password('xxx',"xxxxxx")
['publickey', 'keyboard-interactive']
>>> transport.auth_interactive_dumb('xxx')
[]
>>> client._transport = transport
>>> channel = client.invoke_shell()
>>> channel.send('help')
4
>>> command_result = channel.recv(10240).decode("utf-8")
>>> print(command_result)
/admin1-> help
>>> channel.send('\n')
1
>>> command_result = channel.recv(10240).decode("utf-8")
>>> print(command_result)
[Usage]
show [<options>] [<target>] [<properties>]
[<propertyname>== <propertyvalue>]
set [<options>] [<target>] <propertyname>=<value>
cd [<options>] [<target>]
create [<options>] <target> [<property of new target>=<value>]
[<property of new target>=<value>]
delete [<options>] <target>
exit [<options>]
reset [<options>] [<target>]
start [<options>] [<target>]
stop [<options>] [<target>]
version [<options>]
help [<options>] [<help topics>]
load -source <URI> [<options>] [<target>]
dump -destination <URI> [<options>] [<target>]
/admin1->
>>>