Операционная система (Windows)
Здравствуйте задача зайти на сетевое оборудование и создать новое подключение PPTP с заданными настройками
Решение подключится через телнет к оборудованию и прописать команды
telnet 192.168.1.1
Login: admin
Password:admin
(config)> interface PPTP0
Network::Interface::Repository: «PPTP0» interface created.
(config-if)> interface PPTP0
description Office
role misc
peer k4.office.ru
no ipv6cp
lcp echo 30 3
ipcp default-route
ipcp name-servers
ipcp dns-routes
ccp
security-level public
authentication identity 1234
authentication password 12345
encryption mppe
ip dhcp client dns-routes
ip dhcp client name-servers
ip global 16383
ip tcp adjust-mss pmtu
connect
up
Причем в консоль команды с настройками подключения можно вводить сразу всем блоком в python у меня не получилось это сделать от сюда вытекает первая проблема
Как в код вставить сразу весь блок команд а не выполнять их по одной
большое спасибо за помощь в создании скрипта stud_55@mail.ru
import telnetlib import time ip = ‘192.168.1.1’ user = ‘admin’ password = ‘admin’ loginOffice = ‘1234’ PassOffice = ‘12345’ tn = telnetlib.Telnet(ip) #Автологин tn.read_until(b»Login: «, timeout=5) tn.write(user.encode(‘ascii’) + b»\n») tn.read_until(b»Password: «, timeout=5) tn.write(password.encode(‘ascii’) + b»\n») #Создание PPTP Подключения Офис tn.read_until(b»(config)> «, timeout=5) tn.write(‘interface PPTP0’.encode(‘ascii’) + b»\n») tn.read_until(b»(config-if)> «, timeout=5) tn.write(‘description Office role misc peer k4.office.ru no ipv6cp lcp echo 30 3 ipcp default-route ipcp name-servers ipcp dns-routes ccp security-level public authentication identity 1234 authentication password 12345 encryption mppe ip dhcp client dns-routes ip dhcp client name-servers ip global 16383 ip tcp adjust-mss pmtu connect up’.encode(‘ascii’) + b»\n»)
этот скрипт не работает
import telnetlib import time ip = ‘192.168.1.1’ user = ‘admin’ password = ‘admin’ loginOffice = ‘1234’ PassOffice = ‘12345’ tn = telnetlib.Telnet(ip) #Автологин tn.read_until(b»Login: «, timeout=5) tn.write(user.encode(‘ascii’) + b»\n») tn.read_until(b»Password: «, timeout=5) tn.write(password.encode(‘ascii’) + b»\n») #Создание PPTP Подключения Офис tn.read_until(b»(config)> «, timeout=5) tn.write(‘interface PPTP0’.encode(‘ascii’) + b»\n») tn.read_until(b»(config-if)> «, timeout=5) tn.write(‘description Office role misc peer k4.office.ru no ipv6cp lcp echo ipcp default-route ipcp name-servers ipcp dns-routes ccp security-level public authentication identity loginOffice authentication password PassOffice’.encode(‘ascii’) + b»\n»)
если записывать в одну строку тоже не работает
вторая проблема как задать 1234 в виде переменой loginOffice в authentication identity и 12345 в переменную PassOffice authentication password
import telnetlib import time ip = ‘192.168.1.1’ user = ‘admin’ password = ‘admin’ loginOffice = ‘1234’ PassOffice = ‘12345’ tn = telnetlib.Telnet(ip) #Автологин tn.read_until(b»Login: «, timeout=5) tn.write(user.encode(‘ascii’) + b»\n») tn.read_until(b»Password: «, timeout=5) tn.write(password.encode(‘ascii’) + b»\n») #Создание PPTP Подключения Офис tn.read_until(b»(config)> «, timeout=5) tn.write(‘interface PPTP0’.encode(‘ascii’) + b»\n») tn.read_until(b»(config-if)> «, timeout=5) tn.write(‘description Office’.encode(‘ascii’) + b»\n») tn.read_until(b»(config-if)> «, timeout=5) tn.write(‘role misc’.encode(‘ascii’) + b»\n») tn.read_until(b»(config-if)> «, timeout=5) tn.write(‘peer k4.office.ru’.encode(‘ascii’) + b»\n») tn.read_until(b»(config-if)> «, timeout=5) tn.write(‘no ipv6cp’.encode(‘ascii’) + b»\n») tn.read_until(b»(config-if)> «, timeout=5) tn.write(‘lcp echo 30 3’.encode(‘ascii’) + b»\n») tn.read_until(b»(config-if)> «, timeout=5) tn.write(‘ipcp default-route’.encode(‘ascii’) + b»\n») tn.read_until(b»(config-if)> «, timeout=5) tn.write(‘ipcp name-servers’.encode(‘ascii’) + b»\n») tn.read_until(b»(config-if)> «, timeout=5) tn.write(‘ipcp dns-routes’.encode(‘ascii’) + b»\n») tn.read_until(b»(config-if)> «, timeout=5) tn.write(‘ccp’.encode(‘ascii’) + b»\n») tn.read_until(b»(config-if)> «, timeout=5) tn.write(‘security-level public’.encode(‘ascii’) + b»\n») tn.read_until(b»(config-if)> «, timeout=5) tn.write(‘authentication identity loginOffice’.encode(‘ascii’) + b»\n») tn.read_until(b»(config-if)> «, timeout=5) tn.write(‘authentication password PassOffice’.encode(‘ascii’) + b»\n») tn.read_until(b»(config-if)> «, timeout=5) tn.write(‘encryption mppe’.encode(‘ascii’) + b»\n») tn.read_until(b»(config-if)> «, timeout=5) tn.write(‘ip dhcp client dns-routes’.encode(‘ascii’) + b»\n») tn.read_until(b»(config-if)> «, timeout=5) tn.write(‘ip dhcp client name-servers’.encode(‘ascii’) + b»\n») tn.read_until(b»(config-if)> «, timeout=5) tn.write(‘ip global 16383’.encode(‘ascii’) + b»\n») tn.read_until(b»(config-if)> «, timeout=5) tn.write(‘ip tcp adjust-mss pmtu’.encode(‘ascii’) + b»\n») tn.read_until(b»(config-if)> «, timeout=5) tn.write(‘connect’.encode(‘ascii’) + b»\n») tn.read_until(b»(config-if)> «, timeout=5) tn.write(‘up’.encode(‘ascii’) + b»\n»)
при таком написании команды отрабатываются корректно только в строке
tn.write(‘authentication identity loginOffice’.encode(‘ascii’) + b»\n»)
tn.write(‘authentication password PassOffice’.encode(‘ascii’) + b»\n»)
loginOffice и PassOffice работают не как переменные а как текст