mazer
mazer

Reputation: 171

Reading PuTTY output with c#

What i want: I want to read the Output of the PuttY Window with C#

What I've got: Our company has several hundreds of servers with at least 2-3 technical users (which are running applications). We got a database of all the users and passwords. So it's basically search, copy and paste to login.

What i want to do: Write a piece of software that does this automatically.

How far i am: Wrote a tool, that reads the logfile of a single PuTTY instance and looks for the password prompt. Determinates target user and server (based on current server and su - [username]). Retrieves the password and sends it via PostMessage to a selected PuTTY.

The Problem or what i want to change:

I want to be able to read the PuTTY output directly from the PuTTY window, because the logfile is kind of unreliable (TAB, ESCAPE, etc which scrambles the output). I have used UISpy and other tools to get a control, but no luck.

I don't want to use a keylogger mechanism or something like that.

Maybe a hook or something, but have never done that before.

Additonal Info:

Additonal Info 2: The goal is to write a strict 3rd party software. Not to use other SSH libs, modify PuTTY source or other approaches. The question is: how to read text from the PuTTY window, beside the logfiles.

Upvotes: 15

Views: 5933

Answers (5)

davec
davec

Reputation: 323

Have you considered using OCR?

Sketch of solution would be:

1 - Agent runs waiting to notice a Putty Window (either register a callback with OS for new processes or periodically check the list of running processes)

2 - When a putty is noticed, agent takes screenshot and extracts portion of screen occupied by putty. You would need to extract window location, but can be done via OS calls assuming you have a handle from step 1

3 - Pump this image data into tesseract or something, and get text output back. check to see if the password prompt is there

4 - If prompt is there, it sounds like you had the rest done after this (send info needed via PostMessage)

Upvotes: 2

Aurelia
Aurelia

Reputation: 1062

I don't know why this hasn't been suggested yet, but plink (which is part of the PuTTY suite) is the command-line version of PuTTY, you'll just need to redirect stdin and stdout to get a relatively powerful (as in features, you'll still need to interpret telnet stuff yourself) SSH client.

Upvotes: 4

Louisbob
Louisbob

Reputation: 850

If you can purpose a modified version of putty, you should modify putty sources and including some pipes (or socket) that communicates with your c# application. Like that, your coworker keep the same software.

Upvotes: 0

RAGNO
RAGNO

Reputation: 507

If you are using putty as an SSH tool, use http://www.routrek.co.jp/en/product/varaterm/granados.html C# SSH library

If you are using putty as a serial tool use the inbuilt IO classes

Telnet also has C# libraries, none that I can give any knowledgabel input into what is good.

Upvotes: 0

LaWi
LaWi

Reputation: 71

You should take a look at This Link (Putty StdIn / StdOut. Shows how to open putty from a c# app and how to handle Standard In, Out and Error Output to communicate with your putty instance.

Upvotes: 0

Related Questions