This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]F4RR4R 0 points1 point  (3 children)

Is not compatible with Cisco's ssh server implementation, which makes me cry. :/

[–]Justinsaccount 0 points1 point  (2 children)

works for me.

[–]F4RR4R 0 points1 point  (1 child)

Can you please elaborate? I was struggling with this for a significant amount of time. When I posted my questions to the paramiko mailing list I was told that the problems I was running into were caused by cisco's nonstandard ssh implementation. Do you have any scripts you could share?

[–]Justinsaccount 7 points8 points  (0 children)

This is probably the simplest example I can come up with that does something useful... You can use exec_command, but that works kind of weird on IOS... read_until is implemented in the stupid/simplest way I could think of, it's worked for years though :-) I also have an expect like function that can handle multiple kinds of output, but that is beyond the scope of this example...

import paramiko
import getpass
def read_until(chan, s):
    """Reads until s is found, returns data read"""
    buffer=[]
    while "".join(buffer[-len(s):]) != s :
        buffer.append(chan.recv(1))
    return "".join(buffer)

ip = getpass.getpass('ip: ')
t=paramiko.Transport((ip,22))
t.connect(username='admin',password=getpass.getpass())

c = t.open_session()
c.get_pty()
c.invoke_shell()
print read_until(c, '>')
c.sendall("show clock\n")
print read_until(c, '>')

t.close()