How To Send F2 Key To Remote Host Using Python
Solution 1:
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.
Solution 2:
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.
Post a Comment for "How To Send F2 Key To Remote Host Using Python"