import telnetlib                                                                                                                              
import exceptions                                                                                                                             
                                                                                                                                              
                                                                                                                                              
class no_connect(exceptions.Exception):                                                                                                       
    def __init__(self,args=None):                                                                                                             
        self.args = args                                                                                                                      
                                                                                                                                              
                                                                                                                                              
try:                                                                                                                                          
    try:                                                                                                                                      
        tn = telnetlib.Telnet('xxx.xxx.xxx.xxx')                                                                                              
    except:                                                                                                                                   
        no_connect_flag = 'TRUE'                                                                                                              
                                                                                                                                              
    if no_connect_flag == 'TRUE':                                                                                                             
        raise no_connect                                                                                                                      
                                                                                                                                              
    try:                                                                                                                                      
        tn.set_debuglevel(100)                                                                                                                
    except:                                                                                                                                   
        print 'couldn''t set the debug level'                                                                                                 
                                                                                                                                              
except no_connect:                                                                                                                            
    print 'couldn''t open telnet connection'                                                                                                  


