How to enter program characters for telnet programmatically?

I am using paramiko for ssh in a remote machine, this seems to work fine so far

client.connect(hostname, port=ssh_port, username=username, key_filename=key_fname, password=password)

Now from the remote machine I need to go deeper and using

stdin, stdout, stderr = client.exec_command('telnet localhost %d'%port)

seems to give me the right pens to start talking using stdin.write

My problem is that when I finished, I do not know how to close telnet properly. If I do this manually, I can enter telnet and I see: Escape character is '^]'.I can use Ctrl+]the keyboard and a small menu appears saying

Console escape. Commands are:

 l  go to line mode
 c  go to character mode
 z  suspend telnet
 e  exit telnet

and then I can exit by pressing "e" (it immediately exits without the 'enter' key)

script, stdin.write('^]e'), stdin.write('\^]e'), stdin.write('\c]e'), stdin.write('\M-\C-]e') .. , stdout.read(), script . time.sleep(0.1) ] e, , .

?

+3
1

, .

: '\x1d'

escape- . curses:

from curses.ascii import ctrl
print ctrl(']')
+6

All Articles