Bharat Balegere 's Undocumented Tech Tips

Automate Telnet Commands

Telnet can be used to perform operations like configuring a router.These operations cannot be used in batch files to automate the process.
Ts10 can be used to automate telnet commands in Windows.
Expect can be used to automate telnet commands in Linux.

Example Windows
Restart a Huwaei ADSL2+ router automatically using a batch file
1.Create a text file restart.txt in folder c:\router

192.168.1.1
WAIT "Login: "
SEND "admin\m"
WAIT "Password: "
SEND "admin\m"
WAIT "--> "
SEND "system restart\m"

2.Download Ts10 to c:\router
3.Create a batch file restart.bat in c:\router

chdir C:\router
c:
TST10 /r:restart.txt /o:last_log.txt

Just execute the Restart.bat file to restart your Router.

Example Linux
1.Install Expect : sudo apt-get install expect for ubuntu
2.Create a file restart.sh

#!/usr/bin/expect -f
set timeout 20
set echo  off

set name admin
set routercmd "system restart\r"
# router password
set pass admin
# your router IP address
set routerip 192.168.1.1

spawn telnet $routerip
# send username & password
expect "Login: "
send "$name\r"
expect "Password: "
send "$pass\r"
expect -i "--> "
send $routercmd

exit


3.Make Restart.sh executable

chmod u+x restart.sh

4.Execute the restart.sh script to restart your router.

 

Like This Post ?

RSS Digg Twitter StumbleUpon Delicious Technorati Reddit Facebook Mixx Diigo Google Yahoo

There are no comments yet, add one below.

Leave a Comment


Name (required)

Mail (will not be published) (required)

Website

Comment

Spam Protection by WP-SpamFree