2

I am unable to get Telnet to send only CR (\r) at the end of a command, despite setting the crlf toggle to <CR><NUL> (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 <CR><LF>.
telnet> toggle crlf
Will send carriage returns as telnet <CR><NUL>.
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: 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?

7
  • Can you try either of the solutions in the other question? Either use netcat instead of telnet, or put telnet into binary mode and use either Enter or Control-M at the end of each line. Commented Jun 21, 2019 at 1:47
  • What are you typing after QD? Commented Jun 21, 2019 at 2:27
  • @Mark: I've tried netcat, but don't get a response: $ nc x.x.x.x xxxx, Enter, then QD. Does the device need to be set to listening mode using netcat first? If so, that's not going to be possible. When I put Telnet into binary mode, the ending is LF only, regardless of whether I type Enter or Ctrl-M, which seems really weird, and I get no response from the device. The Ctrl-M idea was clever, so I tested that on my original example, but that made no difference: it ended the line with CRLF as before. @Scott: In my original example I was typing Enter after QD. Commented Jun 21, 2019 at 5:31
  • I have made progress using netcat. The following returns the date, as expected: $ printf 'QD\r' | nc -w 5 x.x.x.x xxxx. Commented Jun 22, 2019 at 4:55
  • 1
    +1 for using netcat rather than telnet. I bet most of this weirdness is coming from the icrnl terminal mode setting. Use stty -a to confirm that it's set. icrnl converts CRs into LFs, so your telnet and netcat are never actually seeing CR from the keyboard. You can stty -icrnl to let CR pass untranslated (and stty icrnl to revert) but then you'll need to use ctrl-J to indicate end-of-line. Commented Jun 24, 2019 at 16:16

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.