Author Topic: How to use telnet from the windows command line and batch files  (Read 661 times)

0 Members and 1 Guest are viewing this topic.

Online Alex EisenhutTopic starter

  • Super Contributor
  • ***
  • Posts: 3704
  • Country: ca
  • Place text here.
I have this seemingly simple task of sending six bytes over telnet in a script. Given my limited software abilities this script will be a simple Windows/DOS-style batch file.

I've tried the plink command from the PUTTy suite and while it does send the string I want to the device, the plink command just stays in the command line's telnet interface.

So after entering a command at the command line like

echo string | plink -load profile

the string is sent, the device responds, but now the command line is stuck in plink's interface rather than just going back to the command line or next line in my batch file.

I've tried the various plink parameters and PUTTy profile settings. It changes nothing to this behaviour.

What utility do you use?
Hoarder of 8-bit Commodore relics and 1960s Tektronix 500-series stuff. Unconventional interior decorator.
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 12105
  • Country: nz
Re: How to use telnet from the windows command line and batch files
« Reply #1 on: April 28, 2026, 04:34:47 am »
I'm not sure how you could that in a polite way with a dumb telnet interface, but you could just start it as a separate window and then wait 2 seconds and kill the task.
Something like this.

start "" /b plink.exe .....
timeout /t 2 >nul
taskkill /im plink.exe /f

But it's not a very nice way of doing it
Greek letter 'Psi' (not Pounds per Square Inch)
 

Online ksjh

  • Regular Contributor
  • *
  • Posts: 100
  • Country: de
Re: How to use telnet from the windows command line and batch files
« Reply #2 on: April 28, 2026, 05:19:12 am »
Would something like netcat/nc/ncat work for your application? I suppose you do not need any of the telnet protocol features and just need to send a few bytes via TCP to a specific port? In this case, ncat could work.
 
The following users thanked this post: abeyer, 5U4GB

Offline IanB

  • Super Contributor
  • ***
  • Posts: 12932
  • Country: us
Re: How to use telnet from the windows command line and batch files
« Reply #3 on: April 28, 2026, 05:41:14 am »
So after entering a command at the command line like

echo string | plink -load profile

the string is sent, the device responds, but now the command line is stuck in plink's interface rather than just going back to the command line or next line in my batch file.

It's maybe unusual that you are piping the string into plink rather than putting is as a parameter to the plink command? The examples in the documentation suggest you would write:

plink -load profile string

Also, and more significantly perhaps, have you tried using the -batch argument to plink so it doesn't come back with a prompt?

Disclaimer, I have never used plink and I'm just scanning the documentation.
 

Offline Ranayna

  • Super Contributor
  • ***
  • Posts: 1218
  • Country: de
Re: How to use telnet from the windows command line and batch files
« Reply #4 on: April 28, 2026, 11:42:16 am »
Install telnet and use it directly?
It's still available in Windows, but it needs to be enabled first.
 

Online Alex EisenhutTopic starter

  • Super Contributor
  • ***
  • Posts: 3704
  • Country: ca
  • Place text here.
Re: How to use telnet from the windows command line and batch files
« Reply #5 on: April 28, 2026, 11:44:49 am »

It's maybe unusual that you are piping the string into plink rather than putting is as a parameter to the plink command? The examples in the documentation suggest you would write:

plink -load profile string

Also, and more significantly perhaps, have you tried using the -batch argument to plink so it doesn't come back with a prompt?

Disclaimer, I have never used plink and I'm just scanning the documentation.

Those were my #1 and #2 tries. Neither worked. The pipe thing was because I saw it online.

I think the -batch option is to prevent plink's output as a program, like maybe a prompt, not the telnet stuff. It changed nothing to the behavior.

Would something like netcat/nc/ncat work for your application? I suppose you do not need any of the telnet protocol features and just need to send a few bytes via TCP to a specific port? In this case, ncat could work.

That's what I also found but it doesn't work. All these software shenanigans assume a background knowledge that ends up having me googling twelve other things. All of a sudden I'm confronted with so many options and new concepts just because I want to send 6 bytes over twisted pair instead of a serial cable.  :-//

At this point making a 1000 foot serial cable with RS-422 is simpler.

I'm not sure how you could that in a polite way with a dumb telnet interface, but you could just start it as a separate window and then wait 2 seconds and kill the task.
Something like this.

start "" /b plink.exe .....
timeout /t 2 >nul
taskkill /im plink.exe /f

But it's not a very nice way of doing it

Yes I suspect there is something in the device I'm telnetting to that also needs something set up. I don't know.

I don't understand why the serial port is so easy and obvious and this telnet thing so obtuse and unobvious.
Hoarder of 8-bit Commodore relics and 1960s Tektronix 500-series stuff. Unconventional interior decorator.
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3947
  • Country: us
Re: How to use telnet from the windows command line and batch files
« Reply #6 on: April 28, 2026, 01:40:32 pm »
Would something like netcat/nc/ncat work for your application? I suppose you do not need any of the telnet protocol features and just need to send a few bytes via TCP to a specific port? In this case, ncat could work.

I agree with this approach. telnet is just a TCP stream to port 23.

ncat is part of the nmap package:  https://nmap.org/ncat/

From command.exe or powershell the syntax to send stuff to an ip address 192.168.1.136 and port 23 is:

echo "blah" | ncat 192.168.1.136 23
 
The following users thanked this post: ksjh

Offline rfclown

  • Frequent Contributor
  • **
  • Posts: 459
  • Country: us
Re: How to use telnet from the windows command line and batch files
« Reply #7 on: April 30, 2026, 02:08:06 am »
we use plink at work to automate testing of our devices which run linux. plink lets one send the password on the command line, whereas other forms of ssh don't allow this. to avoid issues with prompts and such, we use the following syntax:

cmd /c echo | plink.exe -ssh -batch root@192.168.xx.xx -pw "foobar" "linux command here"

this of course is using ssh, not telnet, but PuTTY is supposed to (I think) work with telnet also.
« Last Edit: April 30, 2026, 02:10:58 am by rfclown »
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 12105
  • Country: nz
Re: How to use telnet from the windows command line and batch files
« Reply #8 on: April 30, 2026, 02:15:28 am »
Security wise you have to be careful adding passwords as command line parameters,  But yes.
Greek letter 'Psi' (not Pounds per Square Inch)
 

Online Alex EisenhutTopic starter

  • Super Contributor
  • ***
  • Posts: 3704
  • Country: ca
  • Place text here.
Re: How to use telnet from the windows command line and batch files
« Reply #9 on: May 03, 2026, 08:36:13 pm »
Turns out some of the stuff I was handed is buggy. Even its serial port has issues.
Hoarder of 8-bit Commodore relics and 1960s Tektronix 500-series stuff. Unconventional interior decorator.
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 12105
  • Country: nz
Re: How to use telnet from the windows command line and batch files
« Reply #10 on: May 04, 2026, 02:56:43 am »
If you really want something to send some telnet commands it would be pretty easy to create an app using Python or Lazarus+Indy.

It's simple enough that ChatGPT could create all the code to connect, send some commands over telnet then disconnect.
Its probably only a page of code.

Python would be my recommendation as you could do it in notepad without having to even install an IDE. Just need Python installed.
« Last Edit: May 04, 2026, 02:59:03 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf