i have to send F2 key to telnet host how do i send it using python...using getch() i found that this '<' used for F2 key but while sending its not working..i think there will be some way to send special function keys but i am not able to find it..if somebody knows please help me.thanks in advance
I can't comment (need +1 rep), but you should start by posting the source code you have at the moment.
Extended keys (non-alphanumeric or symbol) are composed of a sequence of single characters, with the sequence depending on the terminal you have told the telnet server you are using. You will need to send all characters in the sequence in order to make it work. Here, using od -c <<< '
CtrlVF2'
I was able to see a sequence of \x1b0Q
with the xterm
terminal.
First, as Ignacio pointed out, you have to determine the exact sequence of characters sent by F2. On my machine, this happens to be ^[OQ
, where ^[
denotes an escape character with ASCII code 27. This is identical to what he got. You have to send the exact same byte sequence over telnet. Assuming that the correct sequence is the one I have shown above, it boils down to this:
import telnetlib
tn = telnetlib.Telnet(HOST, PORT)
tn.write(idpass)
tn.write("\x1b0Q")
tn.close()
In case you are wondering, \x1b
stands for a character having ASCII code 27, since 27 in hexadecimal is 1b
.
This works on my machine (tested by a simple echo server on the receiving end), so if it does not work for you, it means that the remote end expects something else in place of an F2 keypress.