python telnetlib内容输出_使用realtim中的telnetlib读取输出

我正在使用Python的telnetlib对一些机器进行telnet,并执行一些命令,我想得到这些命令的输出。

所以,现在的情况是-tn = telnetlib.Telnet(HOST)

tn.read_until("login: ")

tn.write(user + "\n")

if password:

tn.read_until("Password: ")

tn.write(password + "\n")

tn.write("command1")

tn.write("command2")

tn.write("command3")

tn.write("command4")

tn.write("exit\n")

sess_op = tn.read_all()

print sess_op

#here I get the whole output

现在,我可以用sess-op得到所有的合并输出

但是,我想要的是在command1执行之后和command2执行之前立即获得它的输出,就好像我在另一台机器的外壳中工作一样,如下所示-tn = telnetlib.Telnet(HOST)

tn.read_until("login: ")

tn.write(user + "\n")

if password:

tn.read_until("Password: ")

tn.write(password + "\n")

tn.write("command1")

#here I want to get the output for command1

tn.write("command2")

#here I want to get the output for command2

tn.write("command3")

tn.write("command4")

tn.write("exit\n")

sess_op = tn.read_all()

print sess_op

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值