相关文章推荐
import telnetlib def do_telnet(Host, username, password, finish, commands): import telnetlib print 'hi' '''Telnet远程登录:Windows客户端连接Linux服务器''' # 连接Telnet服务器 tn = telnetlib.Telnet(Host, port=2611, timeout=40) # 输入登录用户名 ## tn.read_until('login: ') ## tn.write(username + '\n') print 'hi' # 输入登录密码 tn.read_until('Password:') tn.write(password + '\n') print 'hi' # 登录完毕后执行命令 print 'hi' print commands tn.write('%s\r\n' % commands) temp = tn.read_all() print "%r",temp #执行完毕后,终止Telnet连接(或输入exit退出) temp = tn.read_until(finish) print("%r",temp) Host = 'xxxxxxxxxxx' # Telnet服务器IP username = 'xxxxxx' # 登录用户名 password = 'xxxxx' # 登录密码 finish = 'Router>' # 命令提示符 commands = 'help' do_telnet(Host, username, password, finish, commands)


如上是代码,问题是,我执行到打印help之后不执行了。