Paramiko在连接到自定义sh后挂起

2024-05-19 17:03:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下脚本来连接到一个自定义sshshell。 当我执行脚本时,它只是挂起。它不执行命令。我怀疑shell有问题,因为它没有任何提示。你知道吗?在

import sys
import os
import paramiko


ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('10.115.130.22', username='admin', password='xxx', timeout = 30)
stdin, stdout, stderr = ssh.exec_command('xconfiguration SystemUnit Name: devicename')
print stdout.readlines()
ssh.close()`

Tags: keyimport脚本hostparamikoosstdoutsys
2条回答

这是一个自定义外壳。它是一个思科ex90视频会议系统。 但是我尝试了不同的命令,比如xconfig,它显示配置。在

我在这个问题上花了太多时间。我发现我需要使用invoke_shell()才能在Tandberg C/E系列视频端点上获得任何超过问候横幅的内容。以下是我的工作代码,FWIW:

import time
import paramiko

command = 'help'

host = 'x.x.x.x'
port = 22
user = 'admin'
passwd = 'TANDBERG'

def tbgShell(host,port,username,password,cmd):
    """send an arbitrary command to a Cisco/TBG gizmo's ssh and 
    get the result"""
    transport = paramiko.Transport((host, port))
    transport.connect(username = user, password = passwd)
    chan = transport.open_channel("session")
    chan.setblocking(0)
    chan.invoke_shell()

    out = ''

    chan.send(cmd+'\n')

    tCheck = 0

    while not chan.recv_ready():
        time.sleep(1)
        tCheck+=1
        if tCheck >= 6:
            print 'time out'#TODO: add exeption here
            return False
    out = chan.recv(1024)

    return out

output = tbgShell(host, port, user, passwd, command)

print output

相关问题 更多 >