3 posts in this topic
i want a script that
"on the beginning of the program it pings to check if there is internet connectivity.
if there is internet connectivity
then it executes my code
else if there is no internet it waits at background to detected internet connectivity then executes my code."
Is this possible
Is there a way, preferably natively within AutoIt, to replicate:
ping -i 2 <nearby_IP>
The ping() function only has an option to set the timeout, but I want to set the TTL to 2 instead.
I want to check whether machine is up or not after we poweron a VM.
So to check that, I am using ping.
With the below command, when we run it, it will capture the value success or not with the errorlevel.
ping -n 1 sinra09-lod11 >nul: 2>nul: so we can track the return code back using below.
echo %errorlevel% So it is able to return the 1 when it is failure and 0 when it is success.
But when I convert the above commands to AutoIT, the return code is always giving 0 even on failure.
MsgBox(0,pingCheck("sinra09-lod11"),"sinra09-lod11") Func pingCheck($system_name) ;$system_name = "sinra09-lod1" $command = @SystemDir&"\ping.exe -n 1 "& $system_name & " >nul: 2>nul:" ConsoleWrite($command) Local $iReturn = RunWait($command) ;MsgBox(0,$system_name,$iReturn) ConsoleWrite($iReturn) if $iReturn = 0 then Return True Else Return False EndIf EndFunc Please suggest..
I have a rather strange issue on some machines.
If I attempt to use the inbuilt PING function, no ICMP packet is sent out.
Ping("internal.fqdn.com") is returning "Host Unreachable"
If I ping using the command prompt, it's all fine.
Using wireshark I can see that it hasn't even attempted an ICMP request. I can see it has looked up DNS to check for the correct IP address (I can see reply packet returns 10 different IP address as round robin - which is expected), but then it simply doesn't send the request.
We seem to be having some connectivity problems with a hosted application vendor. Doing a "ping -t" to the vendor's host reveals that we are dropping packets here and there. I was asked if I could write a script that could run and log these dropped packets.
i put together the code below and initially it was logging a lot of dropped packets - too many really, so I put in Google.com and was still getting a lot of dropped packets. I figured that maybe I was ping flooding and so I added in a Sleep between pings. Now if I run my logger with a ping it running at the same time the command prompt is catching more drops than the app. The only requirement is to date/time stamp these dropped pings. Does anyone have any suggestions on making AutoIT's ping function more like the Windows version?
If $cmdLine <> 2 Then MsgBox(0, "Error", "Script must have 2 parameters to run - Suspect Address & Known Good Address") Exit EndIf $Site1 = $CmdLine ;--> This should be your suspect addr $Site2 = $CmdLine ;--> This should be your known good addr Logfile("STARTING PING SCAN") While 1 $var = Ping($Site1,600) If @error <> 0 Then $var2 = Ping($Site2,600) If $var2 Then; also possible: If @error = 0 Then ... $errstr = $Site1 & " failed to ping, " & $Site2 & " pinged in " & $var2 & " ms" Else $errstr = $Site1 & " failed to ping, " & $Site2 & " also failed to ping" EndIf Logfile($errstr) EndIf Sleep(1500) ;--> Added sleep function in case I was flooding, but now ping -t catches lots of drops that this app doesn't Wend Func LogFile($msg) $file = FileOpen($Site1 & "_log.txt", 1+8) ; Check if file opened for writing OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file. Script will close") Exit EndIf $time = @MON & "-" & @MDAY & "-" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC FileWrite($file, $time & " - " & $msg & @CRLF) FileClose($file) EndFunc