Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

python的telnetlib登录的问题该如何解决?

请问用python的telnetlib进行telnet登录时,连接上去又被ACL拒了然后代码报错。请问该如何处理这个异常,结束这次登陆尝试?

try:
    self.tn = telnetlib.Telnet(host_ip,port=23,timeout=2)
 except:
    logging.warning("failed to connect to host:%s" %host_ip)
    return False
 self.tn.read_until(b'Username:', timeout=3)
 self.tn.write(user_name.encode('ascii') + b'
')
 self.tn.read_until(b'Password:', timeout=3)
 self.tn.write(pass_word.encode('ascii') + b'
') 
 

手动登录测试:
image

代码报错:
image


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...