Sign in to follow this  
Followers 0
prismite

Reading Data from Telnet/Putty/CommandLine

2 posts in this topic

#1 ·  Posted (edited)

I have learned a ton already about Ait and seem to continue learning every day. I'm stuck now trying to figure this next bit out and would appreciate any feedback.

So essentially I have a gui where the user inputs their Username, Password, The MAC Address of their Modem and it's respective IP into 4 seperate fields. Then there is a button that will Telnet or Putty (I can get either to work) to a remote server where it executes a command that runs a quick SNMP test. The thing is ... I'd prefer that window stay hidden and let the test run and just print to the screen the results. 

Step #1 is getting the program to run in the background and still be parse-able when its done.

Step #2 is going to be a P.I.T.A because I'm going to have to RegEx it like nobody's business to get the data out that I want.

See code below

#include <constants.au3>

$SNMPTEST = Run(@ComSpec & " /c " & 'Telnet <serverIP>', "", @SW_SHOW, $STDOUT_CHILD)
Sleep (3000)
Send ("User{ENTER}")
Sleep (2000)
Send ("Password{ENTER}")
Sleep (2000)
Send ("cd /usr/local/tests/bin{ENTER}")
Sleep (1000)
Send ("./snmp.tcl{ENTER}")
Sleep (1000)
Send ("1.1.1.1{ENTER}")
Sleep (5000)
Local $line = ""

while 1
   $line &= StdoutRead($SNMPTEST)
   If @error Then ExitLoop
WEnd

;$TXPOWERFind = StringRegExp ($line, "127.1.2.2.1.3")
;$TXPOWERFound = StringRegExpReplace ($TXPOWERfind[0], "/s*127.1.2.2.1.3", "")

MsgBox (0, "", $line)

Now, for clarity, this excerpt is from a different window outside of the main gui program so that I dont have to deal with the gui while trying to get the function ot work. Normally "user" and "password" are variables and not manual entries, but for this standalone test I dont want to keep getting prompted so I hardcoded them. The IP listed (1.1.1.1) is a theoretical Modem IP.

Also, the bottom two variables (TXPOWER) are all wrong and thats fine ... I have them commented out until I get the 1st section working.  

And Finally i have the msgbox at the end displaying $line solely so I can see if the StdoutRead is producing any kind of data. The code works, but the msgbox returns a blank field. 

What am I missing?

Edited by prismite

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I think that standard telnet does not allow I/O redirection
have a look >here for an alternative to try

Edited by PincoPanco

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0