[Tutor] python telnet slow down.

Rayon evosweet at hotmail.com
Wed Dec 29 11:14:33 CET 2010


Hi I need help with a some telnet automation I am trying build. 
I need to login to a Nortel switch and send a table dump command capture
that data and send it to I file. 
I have the code it, works and does all that I need my problem is that when I
try to dump a table later than 4 mega the it can take hours but when I use
cross talk and do it the manual way it takes 20 min. 
I need to know why and if there are any changes I can make to my code to fix
this. 



#!/usr/bin/env python

import telnetlib
#import telnet_hack

class Telnet_lib:
    
    host = {'server':'','user':'','password':''}
    commands = []
    read_till = ''
    capture_file =''
    
    def fileopen(self,capture_file,data):
        try:
          out_file = open(capture_file,"w")
          out_file.write(data)
        except IOError,error:
            print error
            
    
    def gtt_telnet(self):
        tn = telnetlib.Telnet(self.host['server'])
        tn.set_debuglevel(100)
        tn.read_until('Enter User Name', 3)
        tn.write(self.host['user'] + "\r")
        tn.read_until('Password: ', 3)
        tn.write(self.host['password'] + "\r")
        tn.read_until('HGUO0190.PPC4 V:103', 3)
        for com in self.commands:
            tn.write(com + "\r")
        print 'dump starts'
        tn.read_some()
        #data = tn.read_until(self.read_till)
        #self.fileopen(self.capture_file,data)
 



More information about the Tutor mailing list