- 论坛徽章:
- 0
|
调用python的telnetlib,telnet到目标机发送查询命令,但是回显比较大会分几页显示,需要按回车来显示后面的内容,如果使用自带的read方法来操作,分页间没有eof只能超时后读到第一页内容;如果不使用expect,请问各位有什么好的实现方法读取所有回显内容吗?
def sendcmd(self,cmd,timeout=10):
"""
send cmd to NE
@cmd:ne cmd
B{Example:}
- C{sendcmd(show arp)}
"""
rtn = ''
self.write_tn(cmd+'\n')
self.__tn.read_lazy()
if self.__port ==MTN_PORT:
rtn=self.__tn.read_until("$>",timeout)
elif self.__port==DEV_PORT:
rtn=self.__tn.read_until("->",timeout)
elif self.__port==CLI_PORT:
rtn=self.__tn.read_until("#",timeout)
rtn += self.__tn.read_very_eager()
self.echo_msg(rtn)
if len(rtn) == 0:
self.logger.error('Sorry,command operation failed!')
return rtn
|
|