转自:http://www.xyrland.com/?p=2827
操作步骤
方法:修改telnetlib.py,达到read_until读取的内容显示出来
1.cmd下执行python,然后import telnetlib,telnetlib.__file__就知道源码位置。Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import telnetlib
>>> telnetlib.__file__
'C:\\Python27\\lib\\telnetlib.pyc'
>>> import select
>>> hasattr(select ,"poll")
False
>>>
2.用geany打开telnetlib.py,进行改动编辑
3.修改如下def _read_until_with_select(self, match, timeout=None):
"""Read until a given string is encountered or until timeout.
The timeout is implemented using select.select().
"""
n = len(match)
self.process_rawq()
print self.cookedq#增加这一句
i = self.cookedq.find(match)
if i >= 0:while not self.eof and select.select(*s_args) == s_reply:
i = max(0, len(self.cookedq)-n)
self.fill_rawq()
self.process_rawq()
print self.cookedq#增加这一句
i = self.cookedq.find(match, i)
if i >= 0:def read_very_lazy(self):
"""Return any data available in the cooked queue (very lazy).
Raise EOFError if connection closed and no data available.
Return '' if no cooked data available otherwise. Don't block.
"""
buf = self.cookedq
print buf#增加这一句
self.cookedq = ''
if not buf and self.eof and not self.rawq:
raise EOFError, 'telnet connection closed'
return buf