Can the Windows telnet client be scripted?

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?


Solution 1:

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.

Solution 2:

Yes. Check out this thread.