about Telnetlib problem

JEHERUL jeherul at gmail.com
Wed Mar 10 10:06:28 CET 2010

Dear All

I am trying to telnet to a Cisco router . Following is my code .

#code router.py

import getpass
import sys
import telnetlib

HOST = "router address"               # router address is ommitted for
security reason
user = raw_input("Username : ")
password = getpass.getpass()

tn = telnetlib.Telnet(HOST)

tn.read_until("Username: ")
tn.write(user + "\n")
tn.read_until("Password: ")
tn.write(password + "\n")

tn.write("sh int f0/0")

print "Just to check"

print tn.read_all()

print "after read"

But when I execute the program I got the following error .

Traceback (most recent call last):
  File "router.py", line 23, in ?
    print tn.read_all()
  File "/usr/lib/python2.4/telnetlib.py", line 330, in read_all
  File "/usr/lib/python2.4/telnetlib.py", line 521, in fill_rawq
    buf = self.sock.recv(50)

Please help me .

Jeherul Islam
Indian Institute of Information Technology and Management .
Gwalior (MP)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100310/fd83b5f1/attachment.html>

More information about the Python-list mailing list