Sign in to follow this  
Followers 0
DemonAngel

Telnet Connections Via Autoit

6 posts in this topic

I have a ras server that I connect to via Telnet and get a list of people connected. I would like to know if it is possible to do this via Autoit. Because of Security I am unable to use any 3rd party software. The commands I usualy send to the server is as follows.

telnet {SERVERIP}

{USERNAME}

{PASSWORD}

SH DIALER MAP

This returns a list of connected users in the following format.

Username - IPAddress - PortConnectedON

for up to 30 connections.

Any help would be much appreciated. :think:

Share this post


Link to post
Share on other sites



HI,

hay not sending the command through _RUNDOS(...)

Should work. :think:

May also have a look a : better search for : console (read) for getting the result.

Hope that helps.

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

To my knowledge, there is no native telnet support in Autoit (yet, hehe).

But I had to send some telnet commands via autoit some time ago to reboot my wland harddisk drive and this is what I've been using:

Run("telnet hdd")
   WinWaitActive("Telnet hdd")
   Send("reboot")
   Send("{ENTER}")
   Sleep(2000)
   WinClose("Telnet hdd")

Plain, simple, stupid - and working :think:

Next step would be to grab the output and analyse the content but this is left to the student as an exercise :(

Best regards

Marc

Edited by Marc

It's my job to comfort the disturbed and to disturb the comfortable.

Share this post


Link to post
Share on other sites

Ok , It might be my stupidity to write a post without some code attached. Lets try again.

#include <file.au3>
#include <GuiConstants.au3>
#Include <GuiListView.au3>

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode 

Dim $Contotal = "x"
Dim $DigitalTotal = ""
Dim $AnalogTotal = ""
Dim $Serverip = "10.10.10.10
Dim $WinTitle="Telnet RAS Connection"
Global $xTotal
Global $xAnalog
Global $xIsdn
Global $Filepath = @ScriptDir &"\data4321.log"

GuiCreate("RAS Connection Monitor", 292, 517,(@DesktopWidth-292)/2, (@DesktopHeight-517)/2)

$Button_2 = GuiCtrlCreateButton("Refresh List", 10, 10, 170, 20)
$Button_3 = GuiCtrlCreateButton("Exit", 190, 10, 90, 20)
$Group_4 = GuiCtrlCreateGroup("RAS Connected Information", 10, 40, 270, 90)
$Label_5 = GuiCtrlCreateLabel("Connected ANALOG Users:", 20, 60, 140, 20)
$Label_6 = GuiCtrlCreateLabel("Connected DIGITAL Users:", 20, 80, 140, 20)
$Label_7 = GuiCtrlCreateLabel("Total Connected Users:", 20, 100, 130, 20)
$Label_8 = GuiCtrlCreateLabel("", 160, 100, 110, 20)
$Label_9 = GuiCtrlCreateLabel("", 160, 60, 70, 20)
$Label_10 = GuiCtrlCreateLabel("", 160, 80, 70, 20)
$listview_1 = GUICtrlCreateListView("No|Username|IpAddress|Connection Info",10,140,270,365)

GUISetOnEvent($GUI_EVENT_CLOSE, "EXITDASCRIPT")
GUICtrlSetOnEvent($Button_3, "EXITDASCRIPT")
GUICtrlSetOnEvent($Button_2, "RASRefresh")

GuiSetState()

RASRefresh()

While 1 = 1
Sleep(1000000)
WEnd
Exit

Func RASRefresh()
    $tempgui = GuiCreate("Updating", 361, 22,-1, -1)
    $Progress_1 = GuiCtrlCreateProgress(0, 0, 360, 20)
    GuiSetState()
    
    $pingtest = Ping($Serverip,250)
    If @error Then
        MsgBox(0,"ERROR","Unable to contact RAS server")
        Return
    EndIf
        
    _GUICtrlListViewDeleteAllItems($listview_1)

    Run(".\tn.exe")
    GUICtrlSetData($Progress_1,20)
; Rename window
    WinWait("Telnet","")
    WinSetTitle("Telnet","",$WinTitle)
    WinActivate($WinTitle,"")
    
    ClipPut("10.10.10.10")
    xSend($WinTitle,"{altdown}CRH{altup}")
    xSend("connect","{ctrldown}v{ctrlup}{altdown}C{altup}")
    Sleep(100)
    xSend($WinTitle,"username{ENTER}")
    xSend($WinTitle,"password{ENTER}")
    GUICtrlSetData($Progress_1,40)
    ClipPut($Filepath)
    xSend($WinTitle,"{altdown}TLN{altup}")
    xSend("Open Log File","{ctrldown}v{ctrlup}")
    xSend("Open Log File","{altdown}o{altup}")
    ListConnect()
    GUICtrlSetData($Progress_1,60)
    Sleep(1500)
    GUICtrlSetData($Progress_1,80)
    WinClose($WinTitle,"")
    UpdateData()
    GUICtrlSetData($Progress_1,90)
    logfile()
    GUICtrlSetData($Progress_1,100)
    GUIDelete($tempgui)
EndFunc

Func EXITDASCRIPT()
    Exit
EndFunc 

Func xSend($aWinTitle,$aString)
  Sleep(200)
  WinActivate($aWinTitle,"")
  Send($aString)
Endfunc

Func ListConnect()
  xSend($WinTitle,"sh dialer map{ENTER}")
Endfunc

;-----------------------------------------------------------------------
Func UpdateData()
Dim $aRecords
Dim $xTotal = 0
Dim $xAnalog = 0
Dim $xIsdn = 0


If Not _FileReadToArray("data4321.log",$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf
For $x = 1 to $aRecords[0]
    IF StringInStr($aRecords[$x],"ip") Then $xTotal = $xTotal + 1
    IF StringInStr($aRecords[$x],"Di0") Then $xIsdn = $xIsdn + 1
    IF StringInStr($aRecords[$x],"on As") Then $xAnalog = $xAnalog + 1  
Next

for $counter = 13 to ($aRecords[0] -1) Step 1
$datasearch_name = StringInStr($aRecords[$counter],"name")
$datasearch_on = StringInStr($aRecords[$counter]," on ")
$datasearch_ip = StringInStr($aRecords[$counter],"ip")

$datacalc_length1 = ($datasearch_on - 7) - $datasearch_name
$datacalc_length2 = ($datasearch_name - 1) - ($datasearch_ip + 3)

$data_username = StringMid($aRecords[$counter],($datasearch_name + 5),$datacalc_length1)
$data_ip = StringMid($aRecords[$counter],($datasearch_ip + 3),$datacalc_length2)
$data_Contype = StringMid($aRecords[$counter],($datasearch_on + 3),5)
;MsgBox(0,"",$data_Contype)
GUICtrlCreateListViewItem(($counter - 12) &"|" &$data_username &"|" &$data_ip &"|" &$data_Contype,$listview_1);no|username|ipaddress|info
Next
GUICtrlSetData($Label_8,$xTotal &" of 30 connections")
GUICtrlSetData($Label_9,$xAnalog)
GUICtrlSetData($Label_10,$xIsdn)
If FileExists(".\data4321.log") Then FileDelete(".\data4321.log")
EndFunc
;----------------------------------------------------------------------------------

Func logfile()
$sLogMsg = "Refresh Clicked By "&@UserName
 _FileWriteLog(@WindowsDir &"\rasview.log", $sLogMsg )
EndFunc

Basicly the above script does everything I need. But it creates a log file and then it needs to read the information from there. I wanted to change it so that Autoit will intercept the data and then list it in the gui.

Giving the autoit script the ability to do the function with the use of any other 3rd party software or log files.

Share this post


Link to post
Share on other sites

I have a ras server that I connect to via Telnet and get a list of people connected. I would like to know if it is possible to do this via Autoit. Because of Security I am unable to use any 3rd party software.

:think: Sounds like two contradictory things to me. :(

If AutoIt really is permissible as a script solution and security is really a concern as you say then you'll be using beta functions like the TCP* functions; hotkeying an open window with Send definitely isn't secure...


Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Share this post


Link to post
Share on other sites

Code is check and compiled by myself, hence the only unsecure section would be autoit itself and I kinda trust the good people writing code for the Autoit project. Unless there is something I need to know? :)

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