gpt4 book ai didi

python - 在 Python 3.2 上清除 telnetlib 中的输出缓冲区

转载 作者:太空宇宙 更新时间:2023-11-03 18:56:48 24 4
gpt4 key购买 nike

我想建立一个 telnet 连接,但我不想在终端中看到我写入和读取的内容。例如

tn = telnetlib.Telnet(host)
tn.write(command.encode('ascii') + b"\n")
time.sleep(0.1)
ret = True if b'iconstorage' in self.tn.read_until(b'iconstorage') else False
.
.
.

我不想看到任何东西,但仍然收到

    Telnet(host): send b'command\n'
Telnet(host): recv b'\xff\xfd\x01\xff\xfd\x1f\xff\xfb\x01\xff\xfb\x03\r\r\nls\r\n~ # ls\r\n\x1b[1;34mbin\x1b[0m '
Telnet(host): IAC DO 1
Telnet(host): IAC DO 31
Telnet(host): IAC WILL 1
Telnet(host): IAC WILL 3

.
.
.

有可能避免这种情况吗?提前致谢。

最佳答案

如果您在 Telnet 类的实例上启用了 Debug模式,您应该只会看到类似的内容。

默认情况下, Debug模式处于关闭状态,因此除非您更改了 telnetlib.py,否则您无法使用问题中发布的代码块获得该输出。

无论哪种方式,您都可以通过...显式禁用它

tn = telnetlib.Telnet()
tn.set_debug_level(0)
tn.open(host)
tn.write(command.encode('ascii') + b"\n")
# etc.

关于python - 在 Python 3.2 上清除 telnetlib 中的输出缓冲区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17094135/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com