Jump to content
Sign in to follow this  

Telnet , send couple of commands, results to display

Recommended Posts


First of all I am a newbie so please bear with me.

I was going through couple of threads related to Telnet, but when trying to run, no results.

What I want is to telnet, send couple of commands and show the results. I also want the user to provide the Login credentials to connect instead of hardcoding the information. Commands can be hardcoded.

This is just the beginning of my small automation, once the above target is achieved than I can look to other things later.

Any help will be appreciated.


Share this post

Link to post
Share on other sites

Hi, Ejaz. Have you attempted a forum search? A quick search of "Telnet" turned up a large number of hits, including which demonstrates sending commands. As with the Help file, the Search button is your friend. :)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Share this post

Link to post
Share on other sites

Thank J for replying.

Seriously I am really sorry if you have annoyed by that.

Thats why i mentioned earlier, i was going through many scripts on the forum but none of them even giving any response at all.

I want to see something in the output, even this output after login

"Last login: Mon Sep 10 13:17:06 from

Sun Microsystems Inc. SunOS 5.10 Generic January 2005"

TcpStartUp ()
$RouterIP = tcpconnect("", "23")

Until $RouterIP <> "-1"
While 1

$TCPRecv = TCPRecv($RouterIP,"5000")

;~ ConsoleWrite($TCPRecv) ;for debug test
;~ MsgBox("","",$TCPRecv) ;for debug test

If StringInStr($TCPRecv, "login:") > 0 Then
TCPSend($RouterIP, "userid" & @crlf)
ElseIf StringInStr($TCPRecv, "Password:") > 0 Then
TCPSend($RouterIP, "pass" & @crlf)
TCPSend($RouterIP, "xyz cmd1" & @crlf)
TCPSend($RouterIP, "xyz cmd2" & @crlf)
ElseIf StringInStr($TCPRecv, "END") > 0 Then
Edited by Ejaz

Share this post

Link to post
Share on other sites

So your trying to connect to the IP Address Which generally is a gateway/router address. Unless you are in some massive business network which just HAPPENS to have a telnet server running at that address, attempting to connect via telnet will hang.

Find a real telnet server and try your script out on that. Heres one I think:

Edited by twitchyliquid64

ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search

Share this post

Link to post
Share on other sites

Well I am in a LAN enviornment and it shud not hang, was an example. Like the following wscript work but i want to have this done via Autoit. The following example open the telnet window after taking the user id and pass and then sending few commands and depicting the results.

What I want to achieve is to do this while cmd window is hidden and then the results of the command is stored in a csv file.

Dim objShell

Dim objNetwork

Set objNetwork=CreateObject("WScript.Network")

Set fso = CreateObject("Scripting.FileSystemObject")

Set objShell = CreateObject("Wscript.Shell")





strComputer=InputBox("What server or device do you want to connect to?",_


If Len(strComputer)=0 Then WScript.quit

strUsername=InputBox("Login ID",strTitle,_


If Len (strUsername)=0 Then WScript.Quit

strPassword=InputBox("Your Password?",strTitle,_


If Len (strPassword)=0 Then WScript.Quit

Set objShell=CreateObject("Wscript.shell")

'Start Telnet

objShell.Exec "Telnet " & strComputer

'Give app a chance to get started

WScript.Sleep 2000

objShell.AppActivate "Telnet " & strDefaultServer

'Send login credentials

objShell.Exec strUsername & "~"

WScript.Sleep 500

objShell.Exec strPassword & "~"

WScript.Sleep 500

'Send commands

objShell.Exec "cmd1"

WScript.Sleep 500

objShell.Exec "~"

'Send commands

objShell.Exec "cmd2"

WScript.Sleep 500

objShell.Exec "~"

Do Until objExec.Status

Wscript.Sleep 250


Wscript.Echo objExec.StdOut.ReadAll()

Edited by Ejaz

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...