Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is it possible to use the Windows Telnet client to run a series of commands in a script?

If not are there any alternatives that can be?

share|improve this question
1  
Either you are quite confused about what a telnet client is supposed to be, or you didn't explain your question properly. –  Juliano Jul 17 '09 at 0:48
    
@Juliano: Some telnet clients let you send data to the remote machine using a scripting language to drive the process. Think like "expect" scripts, but wired up to telnet. –  Evan Anderson Jul 17 '09 at 0:52
1  
It might help if you give us an idea of what you're trying to do, as there may be better methods then using the telnet app. –  John Gardeniers Jul 17 '09 at 2:22
    
Like Cygwin, SSH with a password-less Public Key Authentication. superuser.com/questions/6475/… –  nik Jul 17 '09 at 6:40

5 Answers 5

up vote 6 down vote accepted

Ages ago I wrote a COM server to allow me to do telnet from VBScript. If you want a copy (including source) I'd be happy to put it on the Internet somewhere. I use it for remotely rebooting routers.

To give you some idea of what it does, here's an example script (with error checking removed)

const SVR = "www.microsoft.com"
dim telnet, s, i

set telnet = CreateObject("Rhs.Telnet")
telnet.Startup()

telnet.Connect SVR, 80
telnet.Writeline "GET / HTTP/1.0"
telnet.Writeline "Host: www.microsoft.com"
telnet.Writeline "User-Agent: RhsTelnet"
telnet.Writeline "Accept: */*"
telnet.Writeline ""

do while telnet.Readline(s, 1000)
  wscript.echo s
loop

telnet.Disconnect()
telnet.Cleanup()

JR

Link to COM Server: hi Lachlan try http://www.ratsauce.co.uk/RouterCheck.zip

This is the COM server and a script to reboot a Draytek router. The script RouterCheck.wsf checks if it can ping a couple of test hosts, so you'll probably want to ignore most of the code. Just use the RebootRouter function and ignore the rest. This is at the end of my ADSL line so the download may be a bit slow.

If anyone wants the source (Visual C++ 5.0 with ATL) then I can drop it on SourceForge.

share|improve this answer
    
Remotely rebooting routers is what I'm wanting to do also. If you could make your COM server available that would be great. –  LachlanG Jul 17 '09 at 9:05
    
I haven't been able to grab the COM server yet. Is it still there? –  LachlanG Jul 20 '09 at 7:55
    
@Lachlan: My ADSL is now back, so the original link will work again. –  John Rennie Jul 21 '09 at 9:07

Yes. Check out this thread.

share|improve this answer
1  
Zow! Using SendKeys to send keystrokes to the TELNET client. It's a one-way communications channel... I guess it would depend on whether the poster needed to get back data from the TELNET client or not. –  Evan Anderson Jul 17 '09 at 1:11
    
Where there's a will, there's a way :-). –  Adam Brand Jul 17 '09 at 1:20

You could install Perl and use Net::Telnet, which lets you both send and interpret the received data.

ActivePerl is probably the quickest way to get up and running with this:

http://www.activestate.com/activeperl/

And Net::Telnet is documented here:

http://search.cpan.org/~jrogers/Net-Telnet-3.03/lib/Net/Telnet.pm

Further questions about how to code using Net::Telnet probably belong on StackOverflow. You may also want to look at www.perlmonks.org for examples and tips.

share|improve this answer

I know this is a terribly old thread, but I came here from a related question and noticed that a very obvious answer was missed. Ever heard of putty? There's a command line scriptable version called plink.

Plink Howto Plink Executable

share|improve this answer

If you don't mind a commercial solution, there a business telnet client called TeSSH, that has a rich scripting language, and can be run from the command-line. It has support for writting scripts in vbs, perl, and lua. It's fairly inexpensive at $34.95. You can also visit the TeSSH Support Forums.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.