- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我的代码有一些问题。当输出较小时它工作正常,但当输出较大时它会损坏。
这是我的代码:
def listDevices(username, pass, regex):
command = "list-dev " + regex
deviceArray = []
connectString = "plink -ssh -l " + username + " -pw " + pass + " -P " + SshPort + " " + Server + " \"" + command + "\""
rawList = subprocess.check_output(connectString, shell=True)
for line in rawList.split("\r\n"):
if "" is not line:
deviceArray.append(line)
print deviceArray
return deviceArray
Server = 10.10.10.1
SshPort = 22
username = "test"
pass - "password"
regex = "rt*mdr*"
mdrList = listDevices(username, pass, regex)
print mdrList
当数据较小时,此方法可以正常工作,但当数据较大时,此方法会失败。
这是错误:
subprocess.CalledProcessError: Command 'plink -ssh -l test -pw password -P 4000 10.10.10.1 "list-dev *"' returned non-zero exit status 1
编辑:
我替换了plink并编写了paramiko,但仍然没有获取所有数据。这是代码:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip,username=username, password=password, port = 9000)
list =["list-devices rt*"]
command = '\n'.join(list)
print command
stdin,stdout,stderr = ssh.exec_command(command)
print stdout.read()
它给了我以下错误:
Traceback (most recent call last):
File "C:/Users/xx/Scripts/Test2.py", line 31, in <module>
stdin,stdout,stderr = ssh.exec_command(command)
File "C:\Python27\paramiko\client.py", line 404, in exec_command
chan.exec_command(command)
File "C:\Python27\paramiko\channel.py", line 60, in _check
return func(self, *args, **kwds)
File "C:\Python27\paramiko\channel.py", line 229, in exec_command
self._wait_for_event()
File "C:\Python27\paramiko\channel.py", line 1086, in _wait_for_event
raise e
paramiko.ssh_exception.SSHException: Channel closed.
最佳答案
根据plink ssh not working with multiple commands passed in a file. - 65059 - The Cisco Learning Network ,这是 Cisco 路由器的问题,因此与 Python 无关。
SSH using public key authentication to ... - Cisco Support Community表示一旦 Cisco 在输入上看到 EOF,它就会断开连接的两侧,即使根据 TCP 规则,它应该只关闭输入套接字。它建议的解决方法是延迟 EOF,直到所有输出都已下载。它使用快速而肮脏的sleep
,但这对于脚本编写来说是不可靠的。
Putty Dies with Large Output : networking - Reddit说是MTU问题。症状是无法获取超过一屏的信息:
I've come across a few MTU-related issues that manifested in terminal emulators in a similar manner. Usually it's some sort of point-to-point leased line that's carried in a VLAN where the added bytes for tagging mess things up and drop the frame in transit. When that happens, shorter output will go through fine, but longer output will just kill the session. Sometimes gracefully, other times not.
事实上,最后一个似乎是正确的解释。触发连接断开的不是 EOF,而是恰好包含它的命令后面的附加数据。第一个链接的另一个解决方法是在输入命令之间插入几个换行符 - 以这种方式看待事物,它们充当填充,以代替损坏的传输逻辑否则会插入自身并阻塞的填充。
关于python - 当 Cisco 路由器的 ssh 命令产生大量输出时,subprocess.CalledProcessError 和 ssh 连接断开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46964905/
所以我可以在 WSL2 中使用 X11 转发,例如 How to set up working X11 forwarding on WSL2 .然后我在连接到 Cisco AnyConnect 服务器
我最近进入了固件编程领域,我需要您的专家建议来保持我在该领域的初步发展。 我想修改CISCO E2500路由器的固件以增强IPv4和IPv6的路由,其中包括在此过程中更改路由表。 我决定使用 dd
Cisco IOS设置口令—启用口令 可以在全局配置模式下设置启用口令: Router(config)#enable ? last-res
我正在尝试从 Cisco ACI 获取路由表。我收到重复的路线。有办法解决它们吗? 例子: "10.127.32.70/32", "10.127.32.70/32",
我在 Cisco CVP 中有一个外部项目,我已将该项目导入到 Cisco CVP IDE 中。这个项目有一些自定义元素,我也有它们的相关类。我已将它们的相关类放在 cisco\cvp\plugin\
我只想获取打入我们调用中心的所有调用的 3 位信息:调用者、他们调用的号码以及实际接听电话的人的号码(不同于外界调用的号码)。 直到最近,我们通过监听 JTAPI 日志文件更改(使用 Microsof
我有一个文本思科配置。我应该匹配的主机名行是“125-hostname billdevice”。我正在使用下面的模式,但不匹配 true。 Pattern ciscohostname = Patter
只有第一个命令的输出才会写入文件。 如何让它将所有命令的输出写入文件? --- - name: run show commands hosts: nexus1 gather_facts: Fa
我在尝试解析路由器的 mrib 表时遇到了一些问题。我已经能够解析其中的一些但有问题。例如我有以下输出: (192.168.1.1,232.0.6.8) RPF nbr: 55.44.23.1 Fla
我无法让 CharlesProxy 在 Android 或 iOS 设备上运行。笔记本电脑和移动设备位于 Anyconnect VPN 之后。这里的任何指示都会有所帮助。谢谢。 最佳答案 我在 Cha
我有一个 C++ 程序,它使用 Microsoft TAPI 接口(interface)从 Cisco Call Manager PBX 收集调用事件。为了获得 Cisco 事件,我从调用管理器下载了
在我的网页上,我需要检查给定用户是否可以在 Cisco Jabber 客户端上使用。我有号码和用户名。我已经能够发送聊天消息并开始语音对话,但最好检查用户是否在线,例如显示很酷的图标或其他东西。有没有
我已成功使用其他几个 Webex API,但“LstrecordaccessDetailHistory XML 请求”不起作用。 我从 XML 响应中收到此消息: unable to instanti
我目前正在尝试让 RHEL 5 机器通过 radius 访问 cisco acs。我安装了 freeradius 包并使用 radtest 命令尝试访问 radius 服务器。当我进入 cisco r
我希望你能帮助我,目标是使用 pysnmp 获取已连接到 ap 的客户端数量,我想我很接近,我知道我可能必须使用 pyasn1,但我得到了一个给我以下错误的部分: ('-------->', Disp
我正在尝试通过 SNMP 从 ucs-6100 获得答案。 通过控制台:(模拟我的请求) >>> snmpget -v3 -l authPriv -u usr-sha-aes -A authkey1
我在 Ubuntu 20.04 上遇到 Cisco AnyConnect 问题。 当我启动 docker 容器(使用非主机网络驱动程序)时,Cisco AnyConnect 立即重新连接。 启动 do
我正在使用基本的 Cisco VPN 客户端(我相信是 v.5)。无论如何以编程方式确定特定配置文件(或与此相关的任何配置文件)是否已连接? 我希望以某种方式从客户端本身获得状态。我不想尝试 ping
我需要从我的 .NET 应用程序配置和查询 Cisco 路由器,我需要通过 Cisco WSMA 来完成网络服务接口(interface)。 这些服务通过 HTTP(在我的例子中)公开,并使用 SOA
我正在寻找命令行参数,以使用 CISCO H264 将一系列图像转换为 H264。 (类似于 FFMPEG 图像到视频功能)。不幸的是,我不能使用 FFMPEG,因为我正在创建一个商业应用程序,我在其
我是一名优秀的程序员,十分优秀!