telnetlib python示例 [英] telnetlib python example

查看:494
本文介绍了telnetlib python示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在尝试python文档给出的这个非常简单的示例:

So I'm trying this really simple example given by the python docs:

import getpass
import sys
import telnetlib

HOST = "<HOST_IP>"
user = raw_input("Enter your remote account: ")
password = getpass.getpass()

tn = telnetlib.Telnet(HOST)

tn.read_until("login: ")
tn.write(user + "\n")
if password:
   tn.read_until("Password: ")
   tn.write(password + "\n")

tn.write("ls\n")
tn.write("exit\n")
print tn.read_all()

我的问题是它挂在read_all()的末尾.我之前从未使用过此模块,因此在继续之前,我尝试使这个非常基本的示例生效.顺便说一句,我正在使用python 2.4 谢谢.

My issue is that it hangs at the end of the read_all()... It doesn't print anything out. I've never used this module before so I'm trying to get this really basic example to work before continuing. BTW, I'm using python 2.4 Thank you.

推荐答案

好的,我找到了解决方案.在输入ls并退出之前,我需要首先指定终端类型.添加

Okay, I found a solution. Before I entered ls and exit, I needed to first specify the terminal type. Adding

tn.write("vt100\n") 

在"ls"为我解决问题之前.

before the "ls" fixed the problem for me.

这篇关于telnetlib python示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆