【发布时间】:2014-09-09 17:25:15
【问题描述】:
是否有人尝试使用 Paramiko 连接到 Cisco ASA?
我使用以下脚本:
import sys
import os
import paramiko
paramiko.util.log_to_file("ssh_conn.log")
ssh_client = paramiko.SSHClient()
print ('client created')
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print ('key policy set')
ssh_client.connect(hostname='10.10.10.10', username='user', password='pass', port=22)
print ('client connected')
(stdin, stdout, stder) = ssh_client.exec_command('show version')
print ('command sent')
data = stdout.readlines()
print ('data read')
stdout.close()
ssh_client.close()
print ('session closed')
print (data)
它适用于 Cisco IOS(路由器),但当我尝试连接到 ASA 设备时,在“发送命令”后挂起。
Paramiko 日志包含以下消息:
DEB [20140718-18:12:52.534] thr=1 paramiko.transport: starting thread (client mode): 0x23902b0
INF [20140718-18:12:52.537] thr=1 paramiko.transport: Connected (version 2.0, client Cisco-1.25)
DEB [20140718-18:12:52.923] thr=1 paramiko.transport: kex algos:['diffie-hellman-group1-sha1'] server key:['ssh-rsa'] client encrypt:['aes128-cbc', '3des-cbc', 'aes192-cbc', 'aes256-cbc'] server encrypt:['aes128-cbc', '3des-cbc', 'aes192-cbc', 'aes256-cbc'] client mac:['hmac-sha1', 'hmac-sha1-96', 'hmac-md5', 'hmac-md5-96'] server mac:['hmac-sha1', 'hmac-sha1-96', 'hmac-md5', 'hmac-md5-96'] client compress:['none'] server compress:['none'] client lang:[''] server lang:[''] kex follows?False
DEB [20140718-18:12:52.923] thr=1 paramiko.transport: Ciphers agreed: local=aes128-cbc, remote=aes128-cbc
DEB [20140718-18:12:52.924] thr=1 paramiko.transport: using kex diffie-hellman-group1-sha1; server key type ssh-rsa; cipher: local aes128-cbc, remote aes128-cbc; mac: local hmac-sha1, remote hmac-sha1; compression: local none, remote none
DEB [20140718-18:12:53.040] thr=1 paramiko.transport: Switch to new keys ...
DEB [20140718-18:12:53.041] thr=2 paramiko.transport: Adding ssh-rsa host key for 10.10.10.10: b'10d3ea97246086679196bda085796063'
DEB [20140718-18:12:53.066] thr=1 paramiko.transport: userauth is OK
INF [20140718-18:12:53.084] thr=1 paramiko.transport: Authentication (password) successful!
DEB [20140718-18:12:53.084] thr=2 paramiko.transport: [chan 1] Max packet in: 34816 bytes
DEB [20140718-18:12:53.089] thr=1 paramiko.transport: [chan 1] Max packet out: 4096 bytes
INF [20140718-18:12:53.089] thr=1 paramiko.transport: Secsh channel 1 opened.
DEB [20140718-18:12:53.094] thr=1 paramiko.transport: [chan 1] Sesch channel 1 request ok
我在设备上看到活动的 SSH 会话,但我的脚本在输出“命令已发送”后挂起
【问题讨论】:
-
您是否尝试过手动运行 ssh 命令?是否有可能它不会在 stdout 上返回任何数据(而是在 stderr 上)?在这种情况下,stdout.readlines() 可能只是在等待任何内容读取...
-
是的,我尝试通过 SSH 客户端运行命令并且有一些输出。
-
@adamski 写道: 你找到任何问题的答案了吗?实际上我得到了完全相同的结果...将命令发送到 asa 永远不会返回...似乎 SSH 没有提供返回字符来验证命令...顺便说一下,它在交换机和路由器上运行良好...