Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- except (IOError, SystemExit):
- raise
- except KeyboardInterrupt:
- print ("Crtl+C Pressed. Shutting down.")
- import paramiko
- import time
- import re
- import socket
- import os
- ssh = paramiko.SSHClient()
- ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- address = '192.168.1.1'
- username = 'admin'
- password = ''
- ssh.connect(address, port=22, username = username, password = password)
- shell = ssh.invoke_shell(height=400)
- shell.settimeout(2)
- def prompt_console(command = '', channel = shell, timeout = False):
- print(channel.recv(9999).decode('utf-8')) #<-- this is for removing the initial prompt from buffer
- if timeout == False:
- shell.settimeout(3600) #<--increasing the timeout
- channel.send(command+'n')
- log = ''
- while True:
- try:
- log += channel.recv(1).decode('utf-8') #<--every loop it loads a char into the "log" variable
- if log[-9:] == '--More-- ':
- shell.send(" ")
- log.replace('--More-- r rtt','rtt')
- if len(re.findall('.*n',log))>0: #<--it yields every line to python console
- yield log
- log = ''
- except (IOError, SystemExit):
- raise
- except KeyboardInterrupt:
- print ("Crtl+C Pressed. Shutting down.")
Add Comment
Please, Sign In to add comment