Python Telnet server that changes the title of the Putty window

Asked

Viewed 89 times

-1

someone has some Telnet server script that changes the title of the Putty window from whom to connect to it?

1 answer

1

The title change of the "connection window" is not part of the Telnet or SSH protocols, nor does it make sense to - but Putty emulates the behavior of VT100 terminals - and for these, a protocol above the content is defined to change the window title.

The ANSI exhaust sequence "OSC 0; ST" can change the title of the window that connected to the server - it is sufficient that this sequence is printed on the connected terminal. If the connection is to have a Cin login shell operating system, one way to do this is to change the $PS1 environment variable, and include this string within the prompt itself.

Not knowing more of its goals with the telnet connection, and what it has to do with Python is hard to be more specific.

If your Telnet connection is printing the output of the Python program, the above sequence can be displayed with:

print("\x1b]0;{}\x1b\\".format("Seu titulo aqui"))

(In Python, x1b is the representation of the ESC character, the sequence 'ESC + ]" is the command "OSC" - "Operating System Command", and the command "0;" the command to change the terminal title. The "ESC " sequence is the same as "ST" ("STRING TERMINATOR"), which terminates the command). "{}" is used by the method itself .format Python to replace the title you want, leaving the content you want to put in the title of the commands required for this.

The complete documentation of the ANSI control characters is here:

https://en.wikipedia.org/wiki/ANSI_escape_code

Browser other questions tagged

You are not signed in. Login or sign up in order to post.