svss Posted February 16, 2010 Share Posted February 16, 2010 Hi there, i have the following script whci works most of the time for me... ;################################## ;LOGIN Telnet ;################################# Dim $delay = 0, $ip = "x.x.x.x", $passwd = "xxxxxx" FileDelete("C:\xxxx.txt") $delay = Ping($ip) + Ping($ip) + Ping($ip) ;this delay is to be sure that it is enough time to get the prompt back from the switch Run("telnet "&$ip) Sleep(100 + $delay) ControlSend("Telnet", "", "","admin"&@CR) Sleep(100 + $delay) ControlSend("Telnet", "", "",$passwd&@CR) ControlSend("Telnet", "", "",'copy command-output'&@CR) ControlSend("Telnet", "", "","exit"&@CR) ControlSend("Telnet", "", "","yes"&@CR) ControlSend("Telnet", "", "","exit"&@CR) ControlSend("Telnet", "", "","yes"&@CR) WinClose("Telnet") But sometimes the switch comes back with Connection to host lost so the script won`t work anymore i have to manually login to the box and close the cmd box. Is there a way to react to this message? Like sending a "enter" command in this case and start the telnet session again? Thanks for your help Sven Link to comment Share on other sites More sharing options...
Steveiwonder Posted February 16, 2010 Share Posted February 16, 2010 (edited) You should take a look at StdinWrite() StdoutRead() These will allow you to interract with your CMD window Edited February 16, 2010 by Steveiwonder They call me MrRegExpMan Link to comment Share on other sites More sharing options...
svss Posted February 16, 2010 Author Share Posted February 16, 2010 Thanks, had a look at these but so far nothing worked for me.First time i touched them Cheers Sven Link to comment Share on other sites More sharing options...
Steveiwonder Posted February 16, 2010 Share Posted February 16, 2010 I don't know how to use this and fail each time, maybe some of the guru's here can help you out They call me MrRegExpMan Link to comment Share on other sites More sharing options...
svss Posted February 17, 2010 Author Share Posted February 17, 2010 thanks for the reply... seems we are in the same boat. I don`t really understand how to use STDOUT in this case. Hope someone can give me some clues. Thanks Sven Link to comment Share on other sites More sharing options...
notsure Posted February 17, 2010 Share Posted February 17, 2010 (edited) Dont use the telnet from windows, build you own client. #Include <INet.Au3> TcpStartUp () $remoteserver = tcpconnect(TCPNameToIP("www.yourveryniceserver.com"), "23") ;client 2 TELNETserver, leave "TCPNameToIP" out if you have IP only. 23 is telnetport. Do ; do till connected to that server. sleep(100) until $remoteserver <> "-1" While 1 Sleep ('100'); $Recv1 = TCPRecv($remoteserver, "1000");1000 means max stringlen. ;KnockKnock Who's There? $Username = "Boo" $password = "BooWho?" ; Cry baby :D consolewrite($recv1);what the server replies if stringinstr($recv1, "Enter your username") > 0 Then ;Depending what the server replies.. will probably be different in your case. tcpsend($remoteserver, $Username & @crlf) elseif stringinstr($recv1, "Enter your password") > 0 then tcpsend($remoteserver, $password & @crlf) elseif stringinstr($recv1, "Connection to host lost") > 0 then msgbox(16,"error","Connection lost to host");or any other code what to do. EndIf Wend I think this is more the way you want to code this. If you have questions or something, shoot. I'm very experienced with network programming. This is alot better coz you can manipulate the in- and catch the output alot more accurate. Edited February 17, 2010 by notsure Link to comment Share on other sites More sharing options...
Zedna Posted February 17, 2010 Share Posted February 17, 2010 (edited) Dont use the telnet from windows, build you own client. I think this is more the way you want to code this. If you have questions or something, shoot. I'm very experienced with network programming. This is alot better coz you can manipulate the in- and catch the output alot more accurate. I think this is wrong (can be neverending loop): $remoteserver = tcpconnect(TCPNameToIP("www.yourveryniceserver.com"), "23") Do ; do till connected to that server. sleep(100) until $remoteserver <> "-1" It should be $remoteserver = tcpconnect(TCPNameToIP("www.yourveryniceserver.com"), "23") if $remoteserver = -1 Then Exit EDIT: here is more accurate example #737516 Edited February 17, 2010 by Zedna Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search Link to comment Share on other sites More sharing options...
svss Posted February 17, 2010 Author Share Posted February 17, 2010 Thanks a lot that is almost working for me. I altered a wee bit since somtimes the switch asked for username and password Ok is the Exit the right way to close the socket? Also when the message comes up 'Connection to host lost' how can i loop to the initial login again? Thanks a million Sven #Include <INet.Au3> TcpStartUp () $remoteserver = tcpconnect("X.X.X.X", "23") ;client 2 TELNETserver, leave "TCPNameToIP" out if you have IP only. 23 is telnetport. Do ; do till connected to that server. sleep(100) until $remoteserver <> "-1" While 1 Sleep ('100'); $Recv1 = TCPRecv($remoteserver, "1000");1000 means max stringlen. ;KnockKnock Who's There? $Username ='xxxx' $password ='xxxx' ; Cry baby consolewrite($Recv1);what the server replies if stringinstr($Recv1, "Username:") > 0 Then ;Depending what the server replies.. will probably be different in your case. ;msgbox(16,"Username","Username prompt received") TCPSend($remoteserver, $Username & @CRLF) TCPSend($remoteserver, $password & @CRLF) Sleep(500) TCPSend($remoteserver, 'copy command-output ' & @CRLF) Exit ElseIf stringinstr($Recv1, "Password:") > 0 then ;msgbox(16,"passwd","passwd prompt received") Tcpsend($remoteserver, $password & @CRLF) Sleep(500) TCPSend($remoteserver, 'copy command-output' & @CRLF) Exit elseif stringinstr($Recv1, "Connection to host lost") > 0 then msgbox(16,"error","Connection lost to host");or any other code what to do. EndIf Wend Link to comment Share on other sites More sharing options...
JohnOne Posted February 17, 2010 Share Posted February 17, 2010 Glad you are progressing mate. You should put your code inside tags. Quote any reply where you see this to see how #include "AutoItTags" If _Include_tags() Then _code_looks_like_this() EndIf Exit AutoIt Absolute Beginners  Require a serial  Pause Script  Video Tutorials by Morthawt  ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
notsure Posted February 17, 2010 Share Posted February 17, 2010 (edited) EDIT: here is more accurate examplehttp://www.autoitscript.com/forum/index.php?showtopic=104198&view=findpost&p=737516Lol, that's also my post.You're right about the loop tho, but i was only making a fast example for this Thanks a lot that is almost working for me.I altered a wee bit since somtimes the switch askedfor username and password Ok is the Exit the right way to close the socket?Also when the message comes up 'Connection to host lost'how can i loop to the initial login again?Thanks a millionSvenTCPCloseSocket ( socket )And NP, glad i can help. Edited February 17, 2010 by notsure Link to comment Share on other sites More sharing options...
Delta Posted February 18, 2010 Share Posted February 18, 2010 I'm just going to point this out because it's bugging me. This is wrong. elseif stringinstr($Recv1, "Connection to host lost") > 0 then If you lose connection to the host how is the host going to send you "Connection to host is lost"? When you see "Connection to host is lost" in telnet that's literally telnet telling you that it lost connection to the host. [size="1"]Please stop confusing "how to" with "how do"[/size] Link to comment Share on other sites More sharing options...
notsure Posted February 18, 2010 Share Posted February 18, 2010 (edited) I'm just going to point this out because it's bugging me. This is wrong. elseif stringinstr($Recv1, "Connection to host lost") > 0 then If you lose connection to the host how is the host going to send you "Connection to host is lost"? When you see "Connection to host is lost" in telnet that's literally telnet telling you that it lost connection to the host. Hehe, you're right... ill reply later to this. I'm trying to make them too fast, those examples, which gives errors Edited February 18, 2010 by notsure Link to comment Share on other sites More sharing options...
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