Advertisement
Guest User

improved_testing

a guest
Jan 29th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. import getpass
  2. import telnetlib
  3. from time import sleep
  4.  
  5. class Account:
  6.     def __init__(self, login, password, host):
  7.         self.login = login
  8.         self.password = password
  9.         self.host = host
  10.  
  11.     def __repr__(self):
  12.         return "Account (%s:%s @ %s)" % (self.login, self.password, self.host)
  13.  
  14. def connect(user,password,host):
  15.     tn = telnetlib.Telnet(host)
  16.     tn.read_until(b': ')
  17.     tn.write(user.encode('ascii')+b'\n')
  18.     if password:
  19.         tn.read_until(b': ')
  20.         tn.write(password.encode('ascii')+b'\n')
  21.     else:
  22.         tn.read_until(b': ')
  23.         tn.write(b'\n')
  24.     tn.set_debuglevel(10000)
  25.     sleep(1)
  26.     tn.write('ls'.encode('ascii')+b'\n')
  27.     return tn.read_all().decode('ascii')
  28.  
  29. address = input("Enter ip-address: ")
  30. user = input("Enter your login: ")
  31. password = getpass.getpass()
  32.  
  33. acc = Account(user, password, address)
  34. print(acc)
  35.  
  36. connect(acc.login, acc.password, acc.host)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement