Telnet sessions can be automated using the Telnet Scripting Tool v.1.0 written by Albert Yale. I found the utility at How can I reboot my Alcatel SpeedTouch Pro by using a shortcut or a script?, where there is a sample of a text file that can be used to automate a telnet connection. The first line placed in the file contains the IP address of the telnet server followed by the port number to be used (23 is the default port for telnet connections). The subsequent lines contain the strings to wait for from the server, e.g.
WAIT "User :"and to send as responses, e.g.
SEND "\m". The
\mis for a carriage return and linefeed.
Usage Syntax: tst10.exe /r:script.txt [options] /r:script.txt run script.txt [options] any of these: /o:output.txt send session output to output.txt /m run script in minimized window Usage Example: tst10.exe /r:script.txt /o:output.txt /m Scripting Syntax: HOSTNAME PORT port number optional, default: 23 WAIT "string" string to wait for SEND "string" string to send \" represents the a quote character \m represents a <CR/LF> \\ represents the backslash character Scripting Example: hostname.com 23 WAIT "login" SEND "root\m" WAIT "password" SEND "mypassword\m" WAIT ">" SEND "dip internet.dip\m" WAIT ">" Scripting Note: You can start with either WAIT or SEND commands, but you *must* alternate them. ie: you can't use two or more WAIT or SEND in a row. Note: TST will disconnect and close as soon as its done with the last entry of the script. If you need to, you can type in the terminal window while the script is running.
You can use the tool to automate not just sessions where you log into another system via the telnet protocol, but other types of connections where you might use the telnet command.
E.g., I often telnet to the Simple Mail Transfer Protocol (SMTP) port, which is port 25 on mail servers, to troubleshoot connections. The Telnet Scripting Tool (TST) can be used to automate this type of testing as well.
For instance, I created a file, testSMTP.txt, to use
with the Telnet Scripting Tool in timing how long it
was taking a mail server to display its banner. The banner
from mail server software, such as
usually begins with the code
220 mail.example.com ESMTP Sendmail 8.13.8/8.13.8; Mon, 29
Dec 2008 21:39:48 -0500. So, I placed the following commands
in a file to connect to a mail sever at address 192.168.0.5
192.168.0.5 25 WAIT "220" SEND "quit\m"
The first line specifies the IP address of the server followed
by the port number to use, in this case port 25 for an SMTP connection.
WAIT "220" tells the Telnet Scripting Tool to wait
for the string
220 from the server and then to send the
quit command followed by a carriage return and line feed,
e.g. the characters that would be sent if I typed "quit" and hit the
I then opened a command prompt on a Windows XP system and entered the command below:
In this case the file
testSMTP.txt was in the current directory,
but the tst10.exe program was in
Note: before using the program,I uploaded the executable, TST10.exe, to VirusTotal, a service that scans files with many different antivirus programs. It checked the file with 38 antivirus programs. None of them found any malware within the file (see MD5: 4aee641e6ddb9a5fa95f590273729708). Note: the viradd and virsize in the Portable Executable (PE) information stand for "Virtual Address" and "Virtual Size" respectively (see Strange tcpip header?).
Download Locations for TST10.Zip
Petri IT Knowledgebase
TheWorldsEnd.NET - free PHP networking scripts
How can I reboot my Alcatel SpeedTouch Pro by using a shortcut or a script?
By: Daniel Petri
Petri IT Knowledgebase
Telnet Scripting for the DSL-G604T
D-Link DSL-G604T Wireless ADSL Router Support Forum