Sign in to follow this  
Followers 0
mentosan

if ping ok, do telnet

4 posts in this topic

#1 ·  Posted (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 by mentosan

Share this post


Link to post
Share on other sites



ydot you just make a tcp telnet cliant to do that

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 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.

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by FreeFry

Share this post


Link to post
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
Sign in to follow this  
Followers 0