By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,907 Members | 2,031 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,907 IT Pros & Developers. It's quick & easy.

Help please using telnetlib module

P: n/a
Hi Guys,

I just started learning Python a couple of days ago and to put some of
what I learnt into practice. As such I thought I might try and write a
simple program (based on examples I had seen) that would allow me to
log into a Cisco router, enter configuration mode, change an interface
description and also grab a snapshot of the running configuration.

So far I've managed to be able to log in and change the interface
configuration. The tn.read_until() function seems to work pretty much
as I expected however for the life of me I cannot get the running
configuration to display with any of the read functions.

Suggestion code thus far follows:
import getpass
import sys
import telnetlib

#This can actually log in and change an interface description on a
HOST = ""
#user = raw_input("Enter your remote account: ")
#password = getpass.getpass()
password = "tacis345int"

tn = telnetlib.Telnet(HOST)
tn.write(password + "\n")
#if password:
# tn.read_until("Password: ")
# tn.write(password + "\n")
#tn.write("show version\n")
tn.read_until("assword: ")
tn.write("conf t\n")
tn.write("int ethernet0\n")
tn.write("desc This was written by my script\n")
tn.write("show run\n")
print tn.read_very_lazy()
print tn.read_all()
The only output I get from this is:

I have tried the other read options but nothing seems to work for me.
I'm obviously missing something, so if anyone could shed some light
that would be great.

Dec 24 '06 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Simplest explanation is that you can't do a 'show run' from global
configuration mode....

try something like

#exit global configuration mode
print tn.read_until('#')

#disable pause after 24 lines
tn.write('term len 0\n')

#now show the entire running-config
tn.write('show run\n')
print tn.read_until('#')

Dec 24 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.