Can the Windows telnet client be scripted?

Yes. Check out this thread.


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.


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.