0

I'm using telnetlib to connect to a remote telnet server and parse it's response, however, all telnetlib's read_* methods return its raw response - including raw telnet command bytes (starting with 0xFF) - which is undesirable for my purpose.

For example, when calling read_all:
desired output - b'Hello'
output returned by telnetlib - b'\xff\xfd\x18\xff\xfdHello'

Is there a way to make telnetlib exclude those special telnet control bytes from its output?

0x400921FB54442D18
  • 725
  • 1
  • 5
  • 18

1 Answers1

-1

As far as I can tell from your question you need to convert the string into UTF-8. This may be your solution. https://www.tutorialspoint.com/python/string_decode.htm

Richard Payne
  • 283
  • 2
  • 4
  • 16
  • 1
    No, those are telnet control characters and they are not part of the server's shell response and trying to decode such byte sequences would probably result in an invalid unicode string or it would contain unwanted data. – 0x400921FB54442D18 Apr 01 '17 at 17:42
  • In that case there is a question already answered about removing control characters. http://stackoverflow.com/questions/14693701/how-can-i-remove-the-ansi-escape-sequences-from-a-string-in-python – Richard Payne Apr 01 '17 at 17:46
  • Those are not ANSI escape sequences, this is **telnet** control bytes, which is something completely different. – 0x400921FB54442D18 Apr 01 '17 at 17:57