Answer the question
In order to leave comments, you need to log in
How to telnet to Cisco using Python?
Good afternoon.
The task is as follows: using python, make telnet on the Cisco Switch and remove the config from it.
I do it like this:
import getpass
import sys
import telnetlib
HOST = '172.17.0.42'
#user = raw_input("Enter your remote account: ")
password = "mypass"
user = "mylogin"
tn = telnetlib.Telnet(HOST,23,5)
tn.read_until("Username: ", 5)
tn.write(user + "\n")
if password:
tn.read_until("Password: ", 5)
tn.write(password + "\n")
tn.write('sh ver ')
data = ''
while data.find('#') == -1:
data = tn.read_very_eager()
print data
Answer the question
In order to leave comments, you need to log in
It could be even simpler...
1) As you were told to use get_field() +
2)
replace:
on the:
get_field('slider-txt-1') || get_field('slider-txt-2')
1) Read everything from the output after entering the password.
2) type \n after show ver
there is a ciscotelnet module based on telnetlib, specifically for working with cisco via telnet:
pip install git+ https://github.com/sergeyzelyukin/cisco-telnet.git
there is a readme and an example of work on github. quite simple and comfortable.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question