Advertisement
Guest User

Untitled

a guest
Aug 29th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #load this script using the start-on-boot parameter in
  3. #order to back up the switch each time the switch reloads
  4. import telnetlib
  5. import os
  6. import re
  7. import time
  8. import string
  9. import sys
  10. HOST = '127.0.0.1'
  11. PORT = 23
  12. LOGIN_STRING = "Login:"
  13. PASSWORD_STRING = "Password:"
  14. TERMINAL_LEN_ZERO = "terminal length 0\n"
  15. TERMINAL_MONITOR = "terminal monitor\n"
  16. ENABLE_STRING = "enable\n"
  17. CONFIG_STRING = "configure\n"
  18. USERNAME = 'admin'
  19. PASSWORD = 'password'
  20. ENABLE_PASSWORD = ''
  21. TIMEOUT = 3
  22. def do_terminal_settings(tn):
  23. 15 Python Scripting for Dell Networking N-Series | Version 1.0.1
  24.  tn.write(TERMINAL_MONITOR)
  25.  tn.read_until("#")
  26.  tn.write(TERMINAL_LEN_ZERO)
  27.  tn.read_until("#")
  28. def do_login(tn):
  29.  tn.read_until(LOGIN_STRING, TIMEOUT)
  30.  tn.write(USERNAME + "\n")
  31.  tn.read_until(PASSWORD_STRING, TIMEOUT)
  32.  tn.write(PASSWORD + "\n")
  33.  tn.read_until(">", TIMEOUT)
  34.  tn.write(ENABLE_STRING)
  35.  tn.read_until("#", TIMEOUT)
  36. #Replace the “xx.xx.xx.xx” below with the TFTP server IP address
  37. def do_config(tn):
  38.  tn.read_until("#", TIMEOUT)
  39.  tn.write("copy running-config tftp://xx.xx.xx.xx/running-configuration\n");
  40.  tn.read_until("(y/n)", TIMEOUT)
  41.  tn.write("y");
  42.  tn.read_until("#", TIMEOUT)
  43.  
  44. def main():
  45.  telnet = telnetlib.Telnet(HOST,PORT)
  46.  do_login(telnet)
  47.  do_terminal_settings(telnet)
  48.  do_config(telnet)
  49.  telnet.close()
  50.  sys.exit(0)
  51. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement