Skip to content

Instantly share code, notes, and snippets.

@lanbugs
Created June 22, 2018 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lanbugs/2fffeadcd485daad3f801221c33ca9ec to your computer and use it in GitHub Desktop.
Save lanbugs/2fffeadcd485daad3f801221c33ca9ec to your computer and use it in GitHub Desktop.
SSH shell to Cisco devices
#!/usr/bin/env python
import paramiko
import sys
def send_string_and_wait_for_string(command, wait_string, should_print):
shell.send(command)
receive_buffer = ""
while not wait_string in receive_buffer:
receive_buffer += shell.recv(1024)
if should_print:
print receive_buffer
return receive_buffer
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect("10.62.62.10", username="testuser", password="testpasswd", look_for_keys=False, allow_agent=False)
shell = client.invoke_shell()
send_string_and_wait_for_string("", "#", False)
send_string_and_wait_for_string("terminal length 0\n", "#", False)
output=send_string_and_wait_for_string("show logging\n", "#", False)
print output
client.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment