Panzer Baby Posted April 13, 2006 Posted April 13, 2006 Hi All,I'm new to AutoIt so please bear with me. I've tried to find something on the subject through the search function but didn't get any further.What I'm trying to do is open a dos box, dial a certain connection with the rasdial command (everything ok untill here) and then tell the script to open a telnet session and log into a host as soon as it recognizes the text "Successfully Connected to 'Dialup_connection_name'", which is the text you get to see when rasdial has completed. See below:Run("cmd.exe")WinWaitActive("C:\WINNT\system32\cmd.exe")Send("rasdial Dialup_connection_name username password")WinActive("C:\WINNT\system32\cmd.exe", "Successfully connected to ATR001.")WinClose("C:\WINNT\system32\cmd.exe")Run("telnet.exe")WinExists("C:\WINNT\system32\telnet.exe",)Send("open 192.168.191.11{ENTER}")Apparently though, the text in the dosbox cannot be read through the WinExists command, since the dosbox won't close as soon as the connection has been established. Is there another way I should be doing this? The next problem is going to be that I need to enter a login and password in telnet when prompted, and I don't want to work with delays or anything like that as that slows things down unnecessarily and in some cases the delay won't be long enough. I thought maybe to act upon the connection established status by the ProcessExists function but when I look in the taskmanager I can't find the PID of the dialup connection + that would probably be a different PID on another machine, effectively rendering the script useless on another computer.Then I thought about event viewer in control panel => administrative tools, and saw that the connect and disconnect event of a dialup connection each have their own 'number', much like a process id, but I'm wondering if there's a way to use these as a trigger.I hope I'm not asking too many silly questions... but even if I do, your help would be much appreciated!
Simucal Posted April 13, 2006 Posted April 13, 2006 (edited) Wouldnt you be able to StdoutRead() the process and have it check for "Successfully connected to ATR001" ? Check it out in the help file and see if that would suit your needs. Similarly you should be able to StdoutRead() the telnet process to determine when to connect. EDIT: Here is an example I found on the forums. This will run the cmd "ping www.autoitscript.com" and pipe the output to an autoit window. expandcollapse popup; Written by DaveF #include <GuiConstants.au3> ;If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000 GuiCreate("STDIO Window", 425, 322,(@DesktopWidth-425)/2, (@DesktopHeight-362)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) ; Create a read-only edit control $eOutput = GuiCtrlCreateEdit("", 0, 10, 423, 260, BitOR($ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY)) ; Exit button $bExit = GuiCtrlCreateButton("Exit", 340, 285, 60, 20) GuiSetState() ; Run child process and provide console i/o for it. ; Parameter of 2 = provide standard output $ourProcess = Run("ping autoitscript.com", @SystemDir, @SW_HIDE, 2) ; Loop and update the edit control unitl we hit EOF (and get an error) 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) EndIf EndIf $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $bExit ExitLoop Case Else ;;; EndSelect WEnd Exit Edited April 13, 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)
Panzer Baby Posted April 13, 2006 Author Posted April 13, 2006 Wouldnt you be able to StdoutRead() the process and have it check for "Successfully connected to ATR001" ?Check it out in the help file and see if that would suit your needs.Similarly you should be able to StdoutRead() the telnet process to determine when to connect.EDIT:Here is an example I found on the forums. This will run the cmd "ping www.autoitscript.com" and pipe the output to an autoit window.Many thanks simucal, will experiment with that.
Simucal Posted April 13, 2006 Posted April 13, 2006 (edited) If you can give me the exact output of the rasdial and what it says when you connect to the telnet server I can try and whip something up for you real fast. Also, would you like it to display the console information in a gui window like how the example I gave you does? P.S.- Check your PM I sent you Panzer Edited April 13, 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)
Zedna Posted April 13, 2006 Posted April 13, 2006 Look at my sources here: AutoDialIt's my AutoIt project which is for automatic dial/wait/hangup cycling.It's in Czech language only, but you may look into sources for inspiration It's working well and fully tested on WIN98 and WINXP.Note: for dialing, testing connected status and hangup I'm using RNAHELP.EXE on WIN9x (without sources, it's not from me)or RNAHELPXP.EXE on WIN2000 and WINXP (with Delphi sources, it's from me)There are diferrent structures in WIN9x and WINXP for RAS Api functions.Here is code snippet:If @OSTYPE = "WIN32_NT" Then $rnahelp_name = "rnahelpxp.exe" Else $rnahelp_name = "rnahelp.exe" EndIf ; connect: ; returns errorlevel 255 in case of error, 0 in case of success $return = RunWait($rnahelp_name & ' autoconnect "' & $NazevPripojeni & '" ' & $Jmeno & ' ' & $Heslo,'',@SW_HIDE) Sleep(2000); 2s pro jistotu If StavSpojeni() <> 0 Then MsgBox(16, "Chyba", "Chyba c. " & $return & " pri pripojeni!") Exit EndIf ; disconnect: ; returns errorlevel 255 in case of error, 0 in case of success $return = RunWait($rnahelp_name & ' disconnect','',@SW_HIDE) Sleep(2000); 2s pro jistotu If StavSpojeni() = 0 Then MsgBox(16, "Chyba", "Chyba c. " & $return & " pri odpojeni!") Exit EndIf ; test of connected status: Func StavSpojeni() ; Return errorlevel 0, if exactly one dialup network connection is active, otherwise 1 Return RunWait($rnahelp_name & ' status','',@SW_HIDE) EndFuncDelphi source of RNAHELPXP.EXE:expandcollapse popupprogram RnaHelpXp; {$APPTYPE CONSOLE} uses Windows, SysUtils, UnitRasAPI32; procedure Help; begin Writeln('little RNA-Helper for Windows XP, v 1.0'); Writeln('(C) 2005 Petr Zednik, http://www.volny.cz/petr.zednik/'#13#10); Writeln('Usage: RNAHELPXP connect <name>'#13#10); Writeln(' or RNAHELPXP disconnect'#13#10); Writeln(' or RNAHELPXP status'#13#10); Writeln(' or RNAHELPXP autoconnect <name> <username> <pwd>'); Halt(0); end; procedure Connect(const Name: String); begin // zatim neimplementovano ... Halt(0); end; procedure DisConnect(); var I: Integer; Size, Count: DWord; Entries: array[1..10] of TRasConn; Stat: TRASConnStatus; begin Entries[1].dwSize := SizeOf(TRasConn); Size := SizeOf(Entries); if RASEnumConnections(@Entries, Size, Count) <> 0 then Halt(255); Stat.dwSize := SizeOf(Stat); for I := 1 to Count do begin if RasHangUp(Entries[I].RasConn) <> 0 then Halt(255); while RasGetConnectStatus(Entries[I].RasConn, @Stat) <> ERROR_INVALID_HANDLE do Sleep(0); end; Halt(0); end; // Halt(0) if Is Connected // Halt(1) if Is Not Connected procedure Status(); var I: Integer; Size, Count: DWord; Entries: array[1..10] of TRasConn; Stat: TRASConnStatus; begin Entries[1].dwSize := SizeOf(TRasConn); Size := SizeOf(Entries); if RASEnumConnections(@Entries, Size, Count) <> 0 then Halt(1); Stat.dwSize := SizeOf(Stat); for I := 1 to Count do begin if RASGetConnectStatus(Entries[I].RasConn, @Stat) = 0 then if Stat.RasConnState = RASCS_Connected then Halt(0); end; Halt(1); end; procedure AutoConnect(const Name,UserName,Pwd: String); var ParamConn: TRASDialParams; RasdialExt: TRASDialExtensions; ResultRasDial: Integer; HandleConn: HRASConn; ErrText: array[0..255] of Char; begin RasdialExt.dwSize := SizeOf(RasdialExt); RasdialExt.dwfOptions := 0; FillChar(ParamConn, SizeOf(ParamConn), 0); ParamConn.dwSize := SizeOf(TRASDialParams); StrCopy(ParamConn.szEntryName, PChar(Name)); StrCopy(ParamConn.szUserName, PChar(UserName)); StrCopy(ParamConn.szPassword, PChar(Pwd)); ParamConn.szPhoneNumber := ''; ParamConn.szCallbackNumber := ''; ParamConn.szDomain := ''; ParamConn.dwSubEntry := 0; ParamConn.dwCallbackId := 0; HandleConn := 0; ResultRasDial := RasDial(@RasdialExt, nil, @ParamConn, 0, 0, HandleConn); if ResultRasDial <> 0 then begin RasGetErrorString(ResultRasDial, @ErrText, SizeOf(ErrText)); Writeln(ErrText); Halt(255); end; Halt(0); end; var Command: String; begin if ParamCount() = 0 then Help; Command := LowerCase(ParamStr(1)); if Command = 'connect' then Connect(ParamStr(2)) else if Command = 'disconnect' then DisConnect() else if Command = 'status' then Status() else if Command = 'autoconnect' then AutoConnect(ParamStr(2), ParamStr(3), ParamStr(4)) else Help; end. Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search
Panzer Baby Posted April 13, 2006 Author Posted April 13, 2006 Simucal,Yes that would be nice; here's what happens after rasdial:connecting to ATR001...Verifying username and password...Registering your computer on the network...Successfully connected to ATR001.Command completed successfully.Then, in telnet i need to enter:open 192.168.191.11which is followed by login prompt:Login:which is followed by Username promptUser:and that's all.I'm not yet aiming to have this diplayed in a GUIthank you!
Panzer Baby Posted April 13, 2006 Author Posted April 13, 2006 Thank you Zedna, will definitely check out your AutoDial.
Simucal Posted April 14, 2006 Posted April 14, 2006 Alright, here you go Panzer. Originally the example was written by DaveF, has been modified to Automate Panzers Login by Simucal. Requires console telnet. expandcollapse popup#include <GuiConstants.au3> Global $UserName = "Foo", $PassWord = "Bar" ;If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000 GuiCreate("Logon ATR001", 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() ; Run child process and provide console i/o for it. ; Parameter of 2 = provide standard output $ourProcess = Run("rasdial ATR001 fst ATR001", @SystemDir, @SW_HIDE, 2) ; ; Loop and update the edit control unitl we hit EOF (and get an error) 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, "Successfully connected to ATR001.") <> 0 Then ExitLoop EndIf EndIf EndIf $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $bExit ExitLoop Case Else ;;; EndSelect WEnd EnvSet("TELNET_REDIR", "1") $ourProcess = Run(@ProgramFilesDir & "\telnet\telnet.exe 161.58.2.72", @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, "Login:") <> 0 Then StdinWrite($ourProcess, $UserName & @CRLF) EndIf If StringInStr($currentRead, "Password:") <> 0 Then StdinWrite($ourProcess, $PassWord & @CRLF) EndIf EndIf EndIf $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $bExit ExitLoop Case Else ;;; EndSelect WEnd Exit 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)
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