PcExpert Posted June 23, 2006 Posted June 23, 2006 hello, Is it possible to control a telnet session with AutoIt? Thanks! PcExpert
Simucal Posted June 23, 2006 Posted June 23, 2006 (edited) hello,Is it possible to control a telnet session with AutoIt?Thanks!PcExpertYes, but not with Microsoft Telnet. It doesnt use standard IO so you cant stdread/write to the console. Use Console Telnet instead.Then, look in the helpfile for StdoutRead and StdoutWrite. Edited June 24, 2006 by Simucal AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
PcExpert Posted June 24, 2006 Author Posted June 24, 2006 (edited) So I understand that it's not possible to write a code for telnet like this:Telnet("IP-ADRESS", "USERNAME", "PASSWORD", "COMMAND") Edited June 24, 2006 by PcExpert
Simucal Posted June 24, 2006 Posted June 24, 2006 You could write your own function for Console Telnet that would do just that if you wanted. AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
frank10 Posted June 24, 2006 Posted June 24, 2006 Or help me writing an autoit client for telnet, here :http://www.autoitscript.com/forum/index.php?showtopic=28068
Skruge Posted June 24, 2006 Posted June 24, 2006 Is there an HOWTO for making your own UDF?Check http://www.autoitscript.com/autoit3/scite/...F_Standards.htm [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]
PsaltyDS Posted June 24, 2006 Posted June 24, 2006 Check http://www.autoitscript.com/autoit3/scite/...F_Standards.htmOoh... thanks for that link, I hadn't seen that standard before. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
PcExpert Posted June 24, 2006 Author Posted June 24, 2006 Frank10, is your console already making progress? Because I cant actually wait until it's finished.
Simucal Posted June 24, 2006 Posted June 24, 2006 Frank10, is your console already making progress? Because I cant actually wait until it's finished. lol.. just use Console Telnet, like I said PcExpert. Here is an example (original example by DaveF, expanded by yours truely): expandcollapse popup#include <GuiConstants.au3> Global $UserName = "Foo", $PassWord = "Bar", $IPAddress = "vikingmud.org 2001" GuiCreate("Telnet Automation", 425, 322,(@DesktopWidth-425)/2, (@DesktopHeight-362)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) $eOutput = GuiCtrlCreateEdit("", 0, 10, 423, 260, BitOR($ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY)) $bExit = GuiCtrlCreateButton("Exit", 340, 285, 60, 20) GuiSetState() EnvSet("TELNET_REDIR", "1") $ourProcess = Run(@ProgramFilesDir & "\telnet\telnet.exe "&$IPAddress, @ProgramFilesDir & "\telnet", @SW_HIDE, 3) While 1 If $ourProcess Then ; Calling StdoutRead like this returns the characters waiting to be read $charsWaiting = StdoutRead($ourProcess, 0 , 1) If @error = -1 Then $ourProcess = 0 MsgBox(0, "App Exited", "Process has exited...") ContinueLoop EndIf If $charsWaiting Then $currentRead = StdoutRead($ourProcess) GUICtrlSetData($eOutput, $currentRead, 1) If StringInStr($currentRead, "What is your name:") <> 0 Then StdinWrite($ourProcess, $UserName & @LF) EndIf If StringInStr($currentRead, "Password:") <> 0 Then StdinWrite($ourProcess, $PassWord & @LF) EndIf EndIf EndIf $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $bExit ExitLoop Case Else ;;; EndSelect WEnd Exit What that does is telnet to www.vikingmud.org port 2001, and when it sees "What is your name:" it will attempt to send the username. You wont be able to log into the mud in this example however, it doesnt like the @LF character.. but it still serves its purpose. Hopefully this will give you some idea of how to automate telnet. AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
frank10 Posted June 25, 2006 Posted June 25, 2006 (edited) @PCExpert and all: Yes I found out the (silly) error I made. So it's working. But now I must go. See you tomorrow and I will show you the working code. Edited June 25, 2006 by frank10
PcExpert Posted June 25, 2006 Author Posted June 25, 2006 Thanks, frank10! I'm looking forward. PcExpert
frank10 Posted June 26, 2006 Posted June 26, 2006 (edited) Here I am:expandcollapse popup#include <GUIConstants.au3> #include <array.au3> TCPStartup() $router_IP = "192.168.1.10" $port = "23" Dim $ConnectedSocket = -1 $ConnectedSocket = TCPConnect($router_IP , $port ) If $ConnectedSocket = -1 Then MsgBox(16, "Error", "Unable to connect.") Exit EndIf ; Create a GUI for Telnet session: ;============================================== $GOOEY = GUICreate("Telnet client",700,400) $edit = GUICtrlCreateEdit("",10,200,680,350,$WS_DISABLED) $input = GUICtrlCreateInput("",10,10,400,180) $butt = GUICtrlCreateButton("Send",420,10,80,20,$BS_DEFPUSHBUTTON) GUICtrlSetBkColor($edit,0x000000) GUICtrlSetFont ($edit,12) GUISetState() ; array of commands to pass to Telnet to batch control the session (the first is the password) ; the last two in this example are router Command line interpreter: Dim $commands $commands = _ArrayCreate("test", "24", "8", "wan adsl status", "wan adsl perfdata" ) ; check if the array is empty in the while loop: dim $arrEmpty = '1' Dim $msg, $recv, $ret ; GUI Message Loop ;============================================== While 1 ; I put some Sleep, because the connection with the router is slow, so ; I need to wait the response, otherwise I got two different packets ; with two different lines breaked. Sleep('300') $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop ;;; receive part $recv = TCPRecv( $ConnectedSocket, 2048) If @error Then ExitLoop If $recv <> "" Then GUICtrlSetData($edit, " > " & $recv & @CRLF & GUICtrlRead($edit)) ; sends the commands inserted in the array we made, until there is only one element: if $arrEmpty <> 2 then TCPSend( $ConnectedSocket , $commands[0] & @CRLF) $arrEmpty = _ArrayDelete($commands, '0') $arrEmpty = @error ;;; send button: If $msg = $butt Then ; here I check if I want to send an ESC command : If GUICtrlRead($input) = "ESC" Then TCPSend( $ConnectedSocket , Chr ( 27 ) ) Else $ret = TCPSend( $ConnectedSocket , GUICtrlRead($input) & @CRLF) If @ERROR Or $ret < 0 Then ExitLoop EndIf GUICtrlSetData($input,"") GUICtrlSetState($input,$GUI_FOCUS) EndIf WEnd Func OnAutoItExit() If $ConnectedSocket <> - 1 Then TCPCloseSocket($ConnectedSocket) EndIf TCPShutdown() EndFunc;==>OnAutoItExit oÝ÷ Ù8b²+~éܶ*'¶"¶.µ¡#ªÞ¶êçx®¶²¡ûazëlç÷~º&®z¶®¶s`¢6æ6ÇVFRfÇC´uT6öç7FçG2æS2fwC°¢6æ6ÇVFRfÇC¶'&æS2fwC° £²'&öb6öÖÖæG2Fò72FòFVÆæWBFò&F66öçG&öÂFR6W76öâFRf'7B2FR77v÷&B ¤FÒb33cµFVÄ6öÖÖæG0¢b33cµFVÄ6öÖÖæG2Òô'&7&VFRgV÷C·FW7BgV÷C²ÂgV÷C³#BgV÷C²ÂgV÷C³gV÷C²ÂgV÷C·vâG6Â7FGW2gV÷C²ÂgV÷C·vâG6ÂW&fFFgV÷C² ¤FÒb33c·&W7VÇBÒõFVÆæWD&F6b33cµFVÄ6öÖÖæG2¥ô'&F7Æb33c·&W7VÇBÂgV÷C´'&öb&V6VfVB6¶WG2g&öÒFVÆæWBgV÷C² ¤gVæ2õFVÆæWD&F6b33c¶6öÖÖæG2 D57F'GW FÒb33c·&÷WFW%ôÒgV÷C³"ãcããgV÷C° FÒb33c·÷'BÒgV÷C³#2gV÷C° FÒb33c´6öææV7FVE6ö6¶WBÒÓ b33c´6öææV7FVE6ö6¶WBÒD56öææV7Bb33c·&÷WFW%ôÂb33c·÷'B bb33c´6öææV7FVE6ö6¶WBÒÓFVà ×6t&÷bÂgV÷C´W'&÷"gV÷C²ÂgV÷CµVæ&ÆRFò6öææV7BâgV÷C² W@ VæD` ²6V6²bFR'&2V×GâFRvÆRÆö÷ FÒb33c¶'$V×GÒb33³b33° ²'&f÷"FR&V6Vfær6¶WG2g&öÒFVÆæW@ FÒb33c¶'%&W7VÇE³Ð FÒb33c¶×6rÂb33c·&V7bÂb33c·&W@ vÆR 6ÆVWb33³#b33² ²6VæB'&öb6öÖÖæG0 bb33c¶'$V×GfÇC²fwC²"FVà D56VæBb33c´6öææV7FVE6ö6¶WBÂb33c¶6öÖÖæG5³Òfײ5$Äb VÇ6P WDÆö÷ VæD` b33c¶'$V×GÒô'&FVÆWFRb33c¶6öÖÖæG2Âb33³b33² b33c¶'$V×GÒW'&÷ ³³²&V6VfR'@ b33c·&V7bÒD5&V7bb33c´6öææV7FVE6ö6¶WBÂ#C bW'&÷"FVâWDÆö÷ bb33c·&V7bfÇC²fwC²gV÷C²gV÷C²FVàô'&FBb33c¶'%&W7VÇBÂb33c·&V7b tVæ@ D56Æ÷6U6ö6¶WBb33c´6öææV7FVE6ö6¶WB D56WFF÷vâ &WGW&âb33c¶'%&W7VÇ@¤VæDgVæ2³ÓÒfwCµõFVÆæWD&F6So it's a working client telnet window, batchable as we want.The good thing is you can store the values you receive into a variable for every use you want all inside Autoitand without external program like console-telnet or with hacks like writing/reading to file.The only drawback is that there are some characters that are not displaying good. I think the CRLF... I don't know what's the problem up to now. Maybe it's because Telnet uses 7bit char encoding?Can someone help with this char-encoding? It should not be difficult I think.Anyway, for me it's not so important at the moment because I already know which key and commands I want to press and the values I want to parse as the answer:For example here is the confused result from first screen after entering password:7[1;24r8ÿû[;H[2J[5;6HGetting[5;14HStarted[6;8H1.[6;11HGeneral[6;19HSetup[7;8H2.[7;11HWAN[7;15HBackup[7;22HSetup[8;8H3.[8;11HLAN[8;15HSetup[9;8H4.[9;11HInternet[9;20HAccess[9;27HSetup[10;8H[11;6HAdvanced[11;15HApplications[12;8H11.[12;12HRemote[12;19HNode[12;24HSetup[13;8H12.[13;12HStatic[13;19HRouting[13;27HSetup[14;8H14.[14;12HDial-in[14;20HUser[14;25HSetup[15;8H15.[15;12HNAT[15;16HSetup[16;8H[5;43HAdvanced[5;52HManagement[6;45H21.[6;49HFilter[6;56Hand[6;60HFirewall[6;69HSetup[7;45H22.[7;49HSNMP[7;54HConfiguration[8;45H23.[8;49HSystem[8;56HSecurity[9;45H24.[9;49HSystem[9;56HMaintenance[10;45H25.[10;49HIP[10;52HRouting[10;60HPolicy[10;67HSetup[11;45H26.[11;49HSchedule[11;58HSetup[13;45H[14;45H[15;45H[14;45H99.[14;49HExit[21;27HEnter[21;33HMenu[21;38HSelection[21;48HNumber:[1;21HCopyright[1;31H(c)[1;35H1994[1;40H-[1;42H2004[1;47HZyXEL[1;53HCommunications[1;68HCorp.[1;21H[3;31HPrestige[3;40H660HW-61[3;49HMain[3;54HMenu[3;31HIt should be like this:but this one is from adsl router CLI:ras> 7 wan adsl perfdata 77777777777777777 near-end FEC error fast: 0 near-end FEC error interleaved:1434 near-end CRC error fast: 0 near-end CRC error interleaved: 0The latter is readable and parsable. Edited June 26, 2006 by frank10
gseller Posted April 12, 2007 Posted April 12, 2007 Great work frank10! I see the last post was june 2006, just wondering if you have made any progress on this since then. I use telnets exclusively at work to telnet into our telecoms switches all over the world. I am looking to make a telnet application that allows me to keep ip addresses for these switches in an ini file and setup an encrypted login info to use to enter each one. Heard of anything like that? Thanks in advance Jim
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now