Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pexpect
- import sys
- import time
- username = 'admin'
- password = 'test'
- # works with dlink 1210, 3200, DGS-1510,
- #
- #
- def switch_dlink(target_list):
- count = len(target_list)
- print(f'Target count: {count}\n')
- success = 0
- fail = 0
- for i in target_list:
- sys.stdout.write(i + '...')
- sys.stdout.flush()
- try:
- tn = pexpect.spawn('telnet ' + i, timeout=5)
- tn.expect(':')
- tn.sendline(username)
- tn.expect(':')
- tn.sendline(password)
- tn.expect('#')
- tn.sendline('config time_zone operator + hour 2 min 0')
- tn.expect('#')
- #print(tn.before.decode('utf-8'))
- tn.sendline('config sntp primary 10.15.250.6 secondary 0.0.0.0 poll-interval 720')
- tn.expect('#')
- #print(tn.before.decode('utf-8'))
- 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')
- tn.expect('#')
- #print(tn.before.decode('utf-8'))
- tn.sendline('enable sntp')
- tn.expect('#')
- tn.sendline('save')
- tn.expect('#')
- #print(tn.before.decode('utf-8'))
- tn.close()
- success += 1
- sys.stdout.write(" DONE.\n\n")
- sys.stdout.flush()
- except:
- fail += 1
- print(' Host unreachable.\n')
- print(f'Success {success}\n')
- print(f'Fail {fail}\n')
- if __name__ == '__main__':
- try:
- with open('target.list', 'r') as f:
- res = f.read().splitlines()
- target_list = []
- for i in res:
- if len(i) > 0:
- target_list.append(i)
- else:
- pass
- switch_dlink(target_list)
- except:
- print('bad file.')
Add Comment
Please, Sign In to add comment