Solved

Script to establish telnet connection and output results to text file

Posted on 2007-11-19
2
4,383 Views
Last Modified: 2008-02-01
I'm looking to create a script that will do the following:

Connect to several devices (one by one) via telnet, send a couple of commands and save *only* the output of 'status line x' and 'detail line x' to a text file.

To give a better idea, this is what the telnet connection looks like:


~~~~~~~~~~~~~~~~~~~~~~~~

telnet 192.168.1.55
--welcome message --
password prompt > ****** ('password' should be entered by the script)

prompt > status (this 'status' command should be sent by the script)

--status line 1--
--status line 2--
--status line 3--
--status line 4--

prompt > showdetail (this 'showdetail' command should be sent by the script)

--detail line 1--
--detail line 2--
--detail line 3--

prompt > exit

~~~~~~~~~~~~~~~~~~~~~~~~


In the end the output text file should look something like this:

---

device ip: 192.168.1.55
status line 1
status line 4
detail line 3

device ip: 192.168.1.56
status line 1
status line 4
detail line 3

etc...
---
0
Comment
Question by:impersonator
2 Comments
 
LVL 38

Accepted Solution

by:
Shift-3 earned 500 total points
Comment Utility
I'm fairly certain there is no built-in way to do this in Windows (though if there is I'd love to hear about it).

However it should be possible to do it using the free client PuTTY.
http://www.chiark.greenend.org.uk/~sgtatham/putty

It includes a command-line tool called Plink which supports batch scripting.
http://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter7.html#plink
0
 

Author Comment

by:impersonator
Comment Utility
I had already found plink before posting :o).  I ended up using a batch script that calls Expect (http://expect.nist.gov/) + plink to connect to the telnet server then saves the output to a temporary text file which later gets parsed to create the output I want.

thanks.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now