Guest User

Untitled

a guest
Oct 15th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. '''
  2. Created on Aug 25, 2011
  3.  
  4. @author: Gand0lf
  5. '''
  6. import sys
  7.  
  8. from threading import Thread
  9. #Check For Paramiko Dependency
  10. try:
  11.     from paramiko import SSHClient
  12.     from paramiko import AutoAddPolicy
  13. except ImportError:
  14.     print 'Missing Paramiko Dependency.'
  15.     sys.exit(0)
  16.  
  17.  
  18. class Connection (Thread):
  19.     '''
  20. This is the class that checks if a specific
  21. Username and password combination was successful.
  22. '''
  23.  
  24.     def __init__(self,username, password, targetIp, portNumber, timeoutTime):
  25.        
  26.         super(Connection, self).__init__()
  27.        
  28.         self.username = username
  29.         self.password = password
  30.         self.targetIp = targetIp
  31.         self.portNumber = portNumber
  32.         self.timeoutTime = timeoutTime
  33.         self.status = ""
  34.        
  35.     def run(self):
  36.        
  37.         sshConnection = SSHClient()
  38.         sshConnection.set_missing_host_key_policy(AutoAddPolicy())
  39.        
  40.         try:
  41.             sshConnection.connect(self.targetIp, port = self.portNumber, username = self.username,
  42.                                   password = self.password, timeout = self.timeoutTime, allow_agent = False,
  43.                                   look_for_keys = False)
  44.            
  45.             self.status = 'Succeeded'
  46.             sshConnection.close()
  47.         except:
  48.             self.status = 'Failed'
Add Comment
Please, Sign In to add comment