MoonPoint Support Logo

 

Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals



Advanced Search
December
Sun Mon Tue Wed Thu Fri Sat
 
29      
2008
Months
Dec


Mon, Dec 29, 2008 10:29 pm

Scripting Telnet Under Microsoft Windows

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 \m is 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 sendmail, usually begins with the code 220, e.g. 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. The 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 Enter key

I then opened a command prompt on a Windows XP system and entered the command below:

C:\DOCUME~1\JSmith\MYDOCU~1\>"\program files\network\tst10\tst10.exe" /r:testSMTP.txt

In this case the file testSMTP.txt was in the current directory, but the tst10.exe program was in \program files\network\tst10\tst10.exe

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
MoonPoint Support
TheWorldsEnd.NET - free PHP networking scripts

References:

  1. How can I reboot my Alcatel SpeedTouch Pro by using a shortcut or a script?
    By: Daniel Petri
    Petri IT Knowledgebase
  2. Telnet Scripting for the DSL-G604T
    D-Link DSL-G604T Wireless ADSL Router Support Forum

[/network/telnet] permanent link

Mon, Dec 29, 2008 8:37 pm

The Letter "C"

A family member asked me why the English language has the letter "C" when it sounds like "K", e.g. "carp", "clown", or "public", or the letter "S", e.g. "publicity" or the second "c" in "cache", when it appears in words. She wanted to know why we didn't just dispense with the letter altogether. So I did a little online searching with Google and found an explanation at the history of the letter 'C'.

The explanation was that it derives from the Roman use of the letter C to stand for the K sound. The Anglo-Saxons in what is now Great Britain adopted the Roman system. After the Battle of Hastings in which William the Conqueror defeated the Anglo-Saxon forces led by Harold Godwinson many French words became part of the English language. The Norman French pronounced "C" as "S" before the letters "I,E,(Y)". So "C" became a letter with two sounds.

[/languages/english] permanent link

Mon, Dec 29, 2008 2:57 pm

Chopping Strings in BASH

The Bourne-again Shell (BASH) provides built-in mechanisms for extracting substrings from a string.

You can set the value of a variable with myvar="some text". You can view the value of the variable using $myvar or ${myvar}. Putting the "$" in front of the variable name causes BASH to use the value stored in myvar.

$ myvar="some text"
$ echo $myvar
some text
$ echo ${myvar}
some text

There is sometimes an advantage to the format that encloses the variable name in curly braces, i.e. the ${myvar} format.

$ echo "foo$myvar"
foosome text
$ echo "foo$myvarother text"
foo text
$ echo "foo${myvar}other text"
foosome textother text

In the above example, in the instance where the curly braces weren't used, the value of myvar wasn't displayed, because BASH didn't know I wanted myvar rather than myvarother, which has no value assigned to it, so it just dispalyed "foo text". In the second instance where the curly braces were used, BASH could tell I wanted the vaue of myvar and displayed "foo some textother text".

Substrings can be extracted from a string by chopping characters from the beginning and end of a string.

Chopping a trailing character:

You can chop a trailing character from a string in BASH by placing the variable name inside ${ }, such as ${myvar}, and then using %<char>. E.g. suppose myvar has the value "0064092004008999,". To remove the trailing comma from the end of the variable, you could use myvar=${myvar%,}

$ myvar="0064092004008999,"
$ echo ${myvar%,}
0064092004008999

If you wanted to remove the last "9" and all characters that appear after it in the line, you can use "*" in the expression.

$ myvar="0064092004008999,"
$ echo ${myvar%9*}
006409200400899

In the example above, the shortest matching substring is selected and removed, i.e. the "9,". If you wanted to remove the longest matching substring, e.g. every character from the first "9" onwards, you could use

$ myvar="0064092004008999,"
$ echo ${myvar%%9*}
00640

Chopping leading characters:

You can chop leading characters from a string by using # or ##. E.g. suppose myvar has the value "SNMPv2-MIB::sysContact.0 = STRING: John Smith". If you only want the name John Smith, you can use ## to remove the longest substring containing the ":" character. I.e., using myvar=${myvar##*:} wold work. If you instead used only one "#", the shortest matching substring would be removed. I.e., using myvar=${myvar#*:} would return :sysContact.0 = STRING: John Smith, where all characters up to and including the first ":" are removed.

$ myvar="SNMPv2-MIB::sysContact.0 = STRING: John Smith"
$ echo ${myvar##*:}
John Smith
$ echo ${myvar#*:}
:sysContact.0 = STRING: John Smith

References:

  1. Bash by example, Part 1
    Fundamental programming in the Bourne again shell (bash)
    Date: March 1, 2000
    IBM

[/os/unix/bash] permanent link

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo