Scripted telnet access from Windows

Posted by: Roger

Scripted telnet access from Windows - 05/09/2005 12:58

So, we've got a managed switch in our lab that I'd like to reconfigure as part of our automated build process. It's got telnet access, so it should be fairly easy.

What I want are pointers to programs like 'chat' (the one that used to be used with pppd), but that run on Windows and talk telnet.

Suggestions?
Posted by: mlord

Re: Scripted telnet access from Windows - 05/09/2005 13:09

puTTY ?

EDIT: Oh wait, are you specifically after scriptable clients? I suppose so, from the subject line.
Posted by: mlord

Re: Scripted telnet access from Windows - 05/09/2005 13:12

I only know of puTTY, but doubt that it's scriptable enough.

Here's Google's best bet:

http://www.sofotex.com/download/Networking/Telnet/more3.html
Posted by: peter

Re: Scripted telnet access from Windows - 05/09/2005 14:04

Quote:
Suggestions?

Expect?

Peter
Posted by: Roger

Re: Scripted telnet access from Windows - 05/09/2005 14:05

Quote:
EDIT: Oh wait, are you specifically after scriptable clients? I suppose so, from the subject line.


Yeah. The switch has a telnet-accessible command-prompt configuration interface. I want to connect to it, wait for 'Username', send the username, wait for 'Password', send the password, wait for '#', send the command sequence, wait for 'OK', send another command, and so on...

Kinda like I used to have to do with 'chat' with dial-up PPP connections on Linux.

This should all be scriptable from the Windows command line. I don't need any kind of GUI, since it'll all be unattended (when I've finished).

I found a copy of 'expect' in Cygwin, but I don't know if it'll do what I want, and I don't know how to use it, anyway.

I'll take a closer look at your list later, thanks.
Posted by: genixia

Re: Scripted telnet access from Windows - 05/09/2005 14:22

Quote:
Quote:
Suggestions?

Expect?

Peter


Yes, expect is ideal for this task. I've used it before to do exactly this. Basically you give it a string to send, then a range of strings to 'expect' that can trigger different responses. You can set a timeout clause that will trigger if none of the other responses get triggered first etc.

I also used expect to modify my hijack Makefile - I modified the 'install' target to call an expect script that would ftp hijack to my player and reboot it if successful.
Posted by: mlord

Re: Scripted telnet access from Windows - 05/09/2005 15:22

Quote:

I also used expect to modify my hijack Makefile - I modified the 'install' target to call an expect script that would ftp hijack to my player and reboot it if successful.


My install script does something similar, but without expect. It actually performs a full readback of the kernel from flash and compares with the original to ensure correct flash contents before rebooting:

Quote:

echo "Sending kernel.."
ftp -n >/dev/null <<-EOF
open $IP

#passive
site popup 99 Downloading kernel..
put $ZIMAGE /proc/empeg_kernel
site popup 99 Waiting for readback..
get /proc/empeg_kernel /tmp/junk
site popup 0 Done.
quit
EOF
bytes=`ls -l $ZIMAGE|awk '{print $5}'`
dd if=/tmp/junk bs=$bytes count=1 2>/dev/null | diff $ZIMAGE -
if [ "$?" = "0" ]; then
echo "Success!"
else
echo "FAILED -- try again!"
exit 1
fi
rm -f /tmp/junk 2>/dev/null
echo "Rebooting.."
ftp >/dev/null <<-EOF
open $IP

site reboot
EOF


Posted by: shadow45

Re: Scripted telnet access from Windows - 05/09/2005 18:56

You need:

ActivePerl (Since this is on Winders)
Net::Telnet (from Perl CPAN)

Net::Telnet::Cisco automates my whole Cisco switch/router subnet, its a joke how easy it is.
Posted by: Roger

Re: Scripted telnet access from Windows - 05/09/2005 20:19

Quote:
Net::Telnet::Cisco automates my whole Cisco switch/router subnet, its a joke how easy it is.


Looks good. Unfortunately, this is a D-Link .
Posted by: lectric

Re: Scripted telnet access from Windows - 06/09/2005 03:36

Sounds like just about any mud client I've used. Portal was my favorite, tinyfugue is also nice.
Posted by: shadow45

Re: Scripted telnet access from Windows - 06/09/2005 17:07

Net::Telnet will let you automate any telnet session. I've used it for tons of things

Net::Telnet::Cisco is for IOS.. makes it *even* easier