[Tutor] python telnet
Rayon
evosweet at hotmail.com
Wed Aug 19 13:32:57 CEST 2009
using python telnet lib to connect to a Nortel switch, and dump some tables.
My problem is that every now and then the connection is reset by peer .
Telnet Error : (10054, Connection reset by peer)
I need to know why, I have it in a loop so it will download after a few tries but I need to know why.
here is the code.
#main telnet class
import telnetlib
#import telnet lib
class supertelnet: # super tenet class
def __init__(self): # def construct
""""""
def telNetCall(self, Host, User, Pass, LocalFile):
print "start lens dump"
host = Host
user = User
password = Pass
file = LocalFile
telnet = telnetlib.Telnet(host) # connect to telnet client
#telnet.set_debuglevel(1)
telnet.read_until('Enter User Name', 3) # read session data untill match or timeout.
telnet.write(user + '\r') # send username
telnet.write(password + '\r') #send password
# send command to dump len files
# start
print "lens dump in progress"
telnet.write('table ibnlines' + '\r')
telnet.write('format pack' + '\r')
telnet.write('list all' + '\r')
telnet.write('logout' + '\r')
#end of commands
lens = telnet.read_all() # get session data and store data
print "file write strated"
x = open(file,'wd') # open file
x.write(lens) # write data to file
print "file done"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090819/8ba98614/attachment.htm>
More information about the Tutor
mailing list