Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2019
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. import telnetlib
  2. import time
  3.  
  4. ip = '192.168.1.1'
  5. user = 'admin'
  6. password = 'admin'
  7. loginOffice = '1234'
  8. PassOffice = '12345'
  9.  
  10. tn = telnetlib.Telnet(ip)
  11. #Автологин
  12. tn.read_until(b"Login: ", timeout=5)
  13. tn.write(user.encode('ascii') + b"\n")
  14. tn.read_until(b"Password: ", timeout=5)
  15. tn.write(password.encode('ascii') + b"\n")
  16.  
  17. # список команд (переменные вставляются через {} и .format)
  18. l = ['interface PPTP0',
  19.      'description Office',
  20.      'role misc',
  21.      'peer k4.office.ru',
  22.      'no ipv6cp',
  23.      'lcp echo 30 3',
  24.      'ipcp default-route',
  25.      'ipcp name-servers',
  26.      'ipcp dns-routes',
  27.      'ccp',
  28.      'security-level public',
  29.      'authentication identity {}'.format(loginOffice),
  30.      'authentication password {}'.format(PassOffice),
  31.      'encryption mppe',
  32.      'ip dhcp client dns-routes',
  33.      'ip dhcp client name-servers',
  34.      'ip global 16383',
  35.      'ip tcp adjust-mss pmtu',
  36.      'connect',
  37.      'up']
  38.  
  39. for s in l:
  40.     tn.read_until(b"(config)> ", timeout=5)
  41.     time.sleep(1)  # если быстро интервал можно увеличить
  42.     tn.write(s.encode('ascii') + b"\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement