Advertisement
Guest User

Untitled

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