Guest User

Untitled

a guest
Aug 30th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. import pexpect
  2. import sys
  3. import time
  4.  
  5. username = 'admin'
  6. password = 'test'
  7.  
  8. # works with dlink 1210, 3200, DGS-1510,
  9. #
  10. #
  11.  
  12.  
  13.  
  14. def switch_dlink(target_list):
  15. count = len(target_list)
  16. print(f'Target count: {count}\n')
  17. success = 0
  18. fail = 0
  19. for i in target_list:
  20. sys.stdout.write(i + '...')
  21. sys.stdout.flush()
  22. try:
  23. tn = pexpect.spawn('telnet ' + i, timeout=5)
  24. tn.expect(':')
  25. tn.sendline(username)
  26. tn.expect(':')
  27. tn.sendline(password)
  28. tn.expect('#')
  29. tn.sendline('config time_zone operator + hour 2 min 0')
  30. tn.expect('#')
  31. #print(tn.before.decode('utf-8'))
  32. tn.sendline('config sntp primary 10.15.250.6 secondary 0.0.0.0 poll-interval 720')
  33. tn.expect('#')
  34. #print(tn.before.decode('utf-8'))
  35. tn.sendline('config dst repeating s_week last s_day sun s_mth 3 s_time 03:00 e_week last e_day sun e_mth 10 e_time 04:00 offset 60')
  36. tn.expect('#')
  37. #print(tn.before.decode('utf-8'))
  38. tn.sendline('enable sntp')
  39. tn.expect('#')
  40. tn.sendline('save')
  41. tn.expect('#')
  42. #print(tn.before.decode('utf-8'))
  43. tn.close()
  44. success += 1
  45. sys.stdout.write(" DONE.\n\n")
  46. sys.stdout.flush()
  47. except:
  48. fail += 1
  49. print(' Host unreachable.\n')
  50. print(f'Success {success}\n')
  51. print(f'Fail {fail}\n')
  52.  
  53.  
  54. if __name__ == '__main__':
  55. try:
  56. with open('target.list', 'r') as f:
  57. res = f.read().splitlines()
  58. target_list = []
  59. for i in res:
  60. if len(i) > 0:
  61. target_list.append(i)
  62. else:
  63. pass
  64. switch_dlink(target_list)
  65. except:
  66. print('bad file.')
Add Comment
Please, Sign In to add comment