Advertisement
byt3_m3

connect_ssh paramiko

Oct 10th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. def connect_ssh(ip, username, password):
  2.  #Importing paramiko and time modules for use within subroutine
  3.  import paramiko
  4.  import time
  5.  
  6.  remote_conn_pre=paramiko.SSHClient()
  7.  remote_conn_pre
  8.  
  9.  remote_conn_pre.set_missing_host_key_policy(
  10.  paramiko.AutoAddPolicy())
  11.  
  12. #Initiates the connection to remote device
  13.  remote_conn_pre.connect(ip, username=username, password=password, look_for_keys=False, allow_agent=False)
  14.  
  15.  #invokes shell for SSH connection
  16.  remote_conn = remote_conn_pre.invoke_shell()
  17.  print "Interactive SSH session established to " + ip + " with Username:" + username
  18.  print "\nSending commands to device\n"
  19.  sending commands to the device
  20.  remote_conn.send("terminal monitor\n")
  21.  remote_conn.send("terminal length 0\n")
  22.  remote_conn.send("show snmp user \n")
  23.  time.sleep(3)
  24.  output = remote_conn.recv(100000)
  25.  
  26.  print "Results:" + output
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement