Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. 1.1.1.1
  2. 2.2.2.2
  3. 10.10.10.10
  4.  
  5. sdasd
  6. adsadsada
  7. adgfefwef
  8.  
  9. #!/bin/env python
  10. import pexpect
  11. import sys
  12. import time
  13.  
  14.  
  15. username = raw_input("User: ")
  16. password = "AMpt157B"
  17. adduser = "set account name " + username
  18.  
  19.  
  20.  
  21. f = open('file_hosts')
  22. for line in f:
  23. string = line.replace("n","")
  24.  
  25. if len(username) > 0:
  26. #login
  27. login = "ssh -o "ConnectTimeout=2" -o "StrictHostKeyChecking no" admin@"+string
  28. child = pexpect.spawn (login)
  29. child.logfile = open("mylog", "a")
  30. i = child.expect([pexpect.EOF, '[Pp]assword: '])
  31. if i == 0:
  32. print 'No SSH connection for or invalid IP - %s' % (string)
  33.  
  34. if i == 1:
  35.  
  36. child.sendline ('file_passwd')
  37. child.expect ('admin:')
  38. child.sendline(adduser)
  39.  
  40.  
  41. k = child.expect(['Account name already exists', 'Please enter the privilege level :'])
  42.  
  43. if k == 0:
  44. print 'User %s already exists - %s' % (username,string)
  45.  
  46. if k == 1:
  47.  
  48. child.sendline('1')
  49. child.expect ('Please enter the password :')
  50.  
  51. child.sendline(password)
  52. child.expect ('re-enter to confirm :')
  53.  
  54. child.sendline(password)
  55. child.expect ('admin:')
  56.  
  57. child.sendline('exit')
  58.  
  59. print "Username %s was successfuly create in %s" % (username,string)
  60. else:
  61. print "Your input is empty...TRY AGAIN"
  62. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement