Jump to content

if ping ok, do telnet


Recommended Posts

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 by mentosan
Link to comment
Share on other sites

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 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

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 by FreeFry
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...