Dhruv Patel
Dhruv Patel

Reputation: 496

How do I send telnetlib control + c command in python

I am trying to send control + c command in python using telnetlib library. Currently I am doing

tn.write('^]')

But the code above doesn't seem to work. Any clue on What I should use?

Upvotes: 5

Views: 10270

Answers (2)

Iacchus
Iacchus

Reputation: 2838

ctrl+a = decimal 1
ctrl+b = decimal 2
ctrl+c = decimal 3

and so on.. to

ctrl+x = decimal 24
ctrl+y = decimal 25
ctrl+z = decimal 26

escape = 27 etc

Still, for those who will need this in the future

Arrow keys are (3 bytes, decimal)

UP ARROW is 27,91,65 (ESC,'[',A)
DOWN ARROW is 27,91,66 (ESC,'[',B)
RIGHT ARROW is 27,91,67 (ESC, '[',C)
LEFT ARROW is 27,91,68 (ESC, '[',D)

Upvotes: 6

Hussain Shabbir
Hussain Shabbir

Reputation: 14995

Try ASCII characters of control+c to the telnet connection below:-

tn.write('\x03')

Upvotes: 10

Related Questions