Line-ending problem with Telnet: can't remove LF from CRLF when sending command
2
votes
0
answers
5925
views
I am unable to get Telnet to send only CR (
\r
) at the end of a command, despite setting the crlf
toggle to ` (see example below). Instead, Telnet always sends CR-LF (
\r\n`).
My goal: retrieve data from a remote device connected to a cell-modem through an RS-232 port. Currently, I’m using Telnet to send my requests for the data. I have good reasons to believe this is possible, and I need to be able to scale up and automate.
Requirements: the remote device requires that commands end only in CR.
My understanding of the problem: I assume the extra LF is causing the device to fail to properly read my commands. More specifically, I think the LF is left over from each command, and added to the beginning of the next command. I infer this because the very first time I issue a command to the remote device after resetting the device, I actually get the correct response. All subsequent responses, however, indicate the device did not understand the command.
Details: if I launch Telnet, and set it to return hex values (set netdata
, plus set prettydump
to make it easier to read), I can see that the lines end in CR (hex=0d) and LF (hex=0a) even though asked Telnet to end the lines in only CR plus NULL. I.e., I expected the last character to be 00, not 0a. See snippet below (host and port replaced with "x"). FYI: "QD" is my command, which asks the device to report the current date, and "BADD" is the device's response when it doesn't understand a command.
$ telnet
telnet> toggle crlf
Will send carriage returns as telnet .
telnet> toggle crlf
Will send carriage returns as telnet .
telnet> set netdata
Will print hexadecimal representation of network traffic.
telnet> set prettydump
Will print user readable output for "netdata".
telnet> open x.x.x.x xxxx
Trying x.x.x.x xxxx...
Connected to x.x.x.x.
Escape character is '^]'.
QD
> 0x0 51 44 0d 0a
< 0x0 42 41 44 44 0d 0a
BADD
Platforms I have tested: Ubuntu 18.04.1 using Telnet, inetutils-telnet, and PuTTY; Windows 7 using Cygwin, PuTTY, and TeraTerm; Windows 10 using PuTTY.
Similar post: https://unix.stackexchange.com/questions/331109/any-way-to-send-just-n-in-telnet – the question in this other post, however, was the reverse: the line endings needed to be LF only.
Summary of question: how do I get Telnet to send only CR at the ends of lines?
Asked by nuthatch
(21 rep)
Jun 20, 2019, 10:04 PM
Last activity: Jun 25, 2019, 05:30 PM
Last activity: Jun 25, 2019, 05:30 PM