Advertisement
Guest User

Untitled

a guest
Jan 30th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1. #!/usr/bin/python3
  2. import getpass
  3. import telnetlib
  4. from time import sleep
  5.  
  6. class Account:
  7.     def __init__(self, login, password, host):
  8.         self.login = login
  9.         self.password = password
  10.         self.host = host
  11.  
  12.     def __repr__(self):
  13.         return "Account (%s:%s @ %s)" % (self.login, self.password, self.host)
  14.  
  15. def connect(user,password,host):
  16.     data = open('alsVers.txt', 'w')
  17.     tn = telnetlib.Telnet(host)
  18.     tn.read_until(b':')
  19.     tn.write(user.encode('ascii')+b'\n')
  20.     sleep(5)
  21.     if password:
  22.         tn.read_until(b':')
  23.         tn.write(password.encode('ascii')+b'\n')
  24.     else:
  25.         tn.read_until(b':')
  26.         tn.write(b'\n')
  27.     tn.set_debuglevel(10000)
  28.     sleep(5)
  29.     tn.write('enable'.encode('ascii')+b'\n')
  30.     sleep(5)
  31.     tn.write(b'\n')
  32.     sleep(5)
  33.     tn.write('copy tftp://*******/alsitec/24110/als-24110lvt-1.0.0.26f25.stk image2'.encode('ascii')+b'\n')
  34.     sleep(5)
  35.     tn.write('y'.encode('ascii')+b'\n')
  36.     sleep(15)
  37.     tn.write('wr mem'.encode('ascii')+b'\n')
  38.     tn.write('y'.encode('ascii')+b'\n')
  39.     sleep(5)
  40.     alsVers = tn.read_very_eager().decode('ascii').strip(' \n\r\t')
  41.     data.write(str(alsVers))
  42.     data.close()
  43.     tn.write('reload'.encode('ascii')+b'\n')
  44.     tn.write('y'.encode('ascii')+b'\n')
  45.     tn.close()
  46.  
  47. address = input("Enter ip-address: ")
  48. user = input("Enter your login: ")
  49. password = getpass.getpass()
  50.  
  51. acc = Account(user, password, address)
  52. print(acc) #debug
  53.  
  54. connect(acc.login, acc.password, acc.host)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement