13

I need to use telnet to talk with a socket server which is not a standard Telnet server. I do not want any Telnet negotioation or interference of any kind in the data.

This is available as 'raw mode' in PuTTy and I need the same functionality in Linux.

Eden
  • 1,171
  • 1
  • 8
  • 7
  • 2
    [Do you know `netcat`?](http://en.wikipedia.org/wiki/Netcat#Opening_a_raw_connection_to_port_25_.28like_telnet.29) – sr_ Feb 15 '12 at 10:45
  • I added that I need a **command line** telnet client (so Putty on Linux does not work for me). – Eden Feb 15 '12 at 11:47
  • I am connecting to a MOXA product which is a TCP server for remotely connecting to a serial port (of a legacy product). It needs to be _raw_ so that all keystrokes will be sent as is. – Eden Feb 15 '12 at 12:19
  • Basically I need 'telnet-like' functionality but without the protocol. I also tried __netcat__ (suggested above) but that did not work nicely - it is in line edit mode and keystrokes like ^C are not passed. – Eden Feb 15 '12 at 12:23
  • As another pointer, have a look at [`socat`](http://www.dest-unreach.org/socat/), it is a lot more feature-packed than `netcat`; maybe you can utilize it. – sr_ Feb 15 '12 at 12:49
  • Putty's "RAW" mode is not really RAW. When you press Ender, it will send CR/LF. I don't know any other way to type CR other than Enter. – eddyq Mar 10 '20 at 15:32

6 Answers6

13

Use netcat, it provides command line raw sockets, a very handy utility, I often use it to move data between servers when encryption is not required, for example:

Server1

# nc -l -p 1234 | zcat | mysql -u root databaseName

Server2

# mysqldump -u root databaseName | gzip | nc Server1 1234
Geoffrey
  • 334
  • 3
  • 9
  • This is an awesome tip! However, when I tried it between two terminal windows on MacOS the first line errored. My man page for nc says it is an error to use -p with -l. It worked like a champ when I omitted the -p – RufusVS Aug 23 '17 at 03:51
5

At risk of sounding daft, why not just use PuTTY? If you already like the functionality it gives you, just run it. PuTTY is available for Linux or Windows

As already pointed out in comments, telnet isn't raw - it expects certain protocols to be followed.

Rory Alsop
  • 2,063
  • 15
  • 30
2

You can use telnet to connect to any port provided that there is something listening to that port and it is not blocked by a firewall.

telnet alt1.aspmx.l.google.com 25
telnet google.com 80

Will all work fine. However, you must know what protocol is used by the other end of the connection otherwise, it is kind of pointless.

Note that telnet sends packets unencrypted.

  • 5
    Beware: telnet seems "raw", but it isn't. There is already some protocol level involved even if limited. What are you trying to achieve here ? – Ouki Feb 15 '12 at 10:21
  • @Ouki, the TELNET *protocol* is quite complex, sure. The telnet *'program* will usually revert to a raw operation mode if not connecting to a TELNET server. – vonbrand Feb 23 '20 at 03:55
0

Very old, but I found this to work for a MOXA unit:

stty raw && nc <ip> 23 && stty sane
Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
smp
  • 11
  • 1
0

Still relevant after all these years.

This works fine in the ~/.bash_aliases, opening up a moxa shell in a tab without the local echo: (parameter is moxa port number)

function moxat(){
  mate-terminal --tab --title="moxa1 $1" -e "bash -c 'stty raw -echo && \ 
  nc <ip> $1 && stty sane'" 
}
Paulo Tomé
  • 3,754
  • 6
  • 26
  • 38
OMR
  • 1
-1

Use this exact line:

sudo socat tcp-l:2023,reuseaddr,fork exec:/bin/login,pty,setsid,setpgid,stderr,ctty

That will let you connect with a raw socket from the Moxa and get a command line prompt on the host machine. From there you can Telnet or SSH at will to any system with ease.

jasonwryan
  • 71,734
  • 34
  • 193
  • 226