Search code examples
pythontelnettelnetlib

Send byte through Telnet in Python


In a Python script, I need to send a single byte through Telnet, with value 0x06, for example. However, the write function from telnetlib (Telnet.write(buffer)) only takes strings as argument.

The conversion using str(0x06) does not work, as its output converts the number to an array of chars, while what I want is a char whose value is 0x06.

So basically, how does one send a single byte through Telnet using Python?


Solution

  • You can use:

    Telnet.write( chr(27) )
    

    or

    Telnet.write( "\x1b" )
    

    to write one single byte for instance.