Question

I want to establish one telnet connection but I don't want to see in the terminal what I write and read. e.g.

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
.
.
.

I don't want to see anything but still receive

    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

.
.
.

Is it possible to avoid that? Thanks in advance.

Was it helpful?

Solution

You should only be seeing things like that if you've enabled debug mode on that instance of the Telnet class.

Debug mode is off by default, so unless you've changed telnetlib.py, there's no way you can get that output with the code block you posted in the question.

Either way, you can explicitly disable it with...

tn = telnetlib.Telnet()
tn.set_debug_level(0)
tn.open(host)
tn.write(command.encode('ascii') + b"\n")
# etc.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top