mentosan Posted July 11, 2008 Share Posted July 11, 2008 (edited) Hello I want to set a condition for my script : do send telnet commands as long as ping is OK. Here is my code : #include <file.au3> Dim $ipfile="host.txt" Dim $ipadress HotKeySet("^c", "ExitProgram") _FileReadToArray ($ipfile, $ipadress) $ping = Run ("ping " & $ipadress[1] & "{Enter}", @SW_HIDE) Run ("telnet -f log_telnet.txt") WinActivate("system32") WinWaitActive("system32") Send ("open " & $ipadress[1] & "{Enter}") WinWaitActive("Telnet " & $ipadress[1]) Send ("password" & "{Enter}") Do $hoststatus = StdoutRead ($ping) sleep (2000) Until $hoststatus <> "Request timed out" ControlSend ("Telnet","","","show calendar" & "{Enter}") Func ExitProgram() Exit (0) EndFunc Any help would be appreciated. Edited July 11, 2008 by mentosan Link to comment Share on other sites More sharing options...
7h331337 Posted July 11, 2008 Share Posted July 11, 2008 ydot you just make a tcp telnet cliant to do that Link to comment Share on other sites More sharing options...
archgriffin Posted July 11, 2008 Share Posted July 11, 2008 (edited) Wouldn't this work better for the ping then opening part? If Ping($ipadress) Then Run ("telnet " & $ipaddress & " -f " & $ipaddress & "_log_telnet.txt") ...Other Code Here... Else MsgBox(0, "Failure", $ipaddress & " is not pingable.") EndIf Beyond that I'm not a telnet style person. Edited July 11, 2008 by archgriffin "Human kind cannot gain anything without first giving something in return, to obtain; something of equal value must be lost."The Help File is truly your friend. Link to comment Share on other sites More sharing options...
FreeFry Posted July 11, 2008 Share Posted July 11, 2008 (edited) He could also use this function I posted in another thread, to make a more "reliable" ping to the host: Func _Ping($svHost, $ivTimeOut = 1000, $ivTries = 4, $ivSleepTime = 1000) Local $avPing[$ivTries+1][2] = [[0]], $ivDivider = 0 For $i = 1 To $ivTries $avPing[$i][0] += Ping($svHost, $ivTimeOut) $avPing[$i][1] = @error $avPing[0][0] += $avPing[$i][0] If $avPing[$i][1] Then $avPing[0][1] += 1 $ivDivider += (Not $avPing[$i][1]) Sleep($ivSleepTime) Next Return(SetError($avPing[0][1], Int($avPing[0][0]/$ivDivider), $avPing)) EndFunc And check @error for # of pings that failed out(like If @Error > 0 Then ; Error Code ) Edited July 11, 2008 by FreeFry 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