Jump to content

Logging dropped pings using AutoIT not matching DOS' ping -t


Go to solution Solved by j0kky,

Recommended Posts

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[0] <> 2 Then
    MsgBox(0, "Error", "Script must have 2 parameters to run - Suspect Address & Known Good Address")
    Exit
EndIf

$Site1 = $CmdLine[1] ;--> This should be your suspect addr
$Site2 = $CmdLine[2] ;--> 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
Link to comment
Share on other sites

Thanks for the quick reply PainTain.  I'm not exactly sure how to do that, but wouldn't I be in the same boat with a single "DOS" ping?  I would still either be pinging too much or too little, right? And I really don't know how / if I could parse a ping -t.

Link to comment
Share on other sites

Thanks computergroove, I will read up on that.  I wouldn't be able to use that with "ping -t" and still get the desired results would I? (logging the date/time of each dropped ping)  I'm still interested on why using the DOS ping is any better than using AutoIT's ping and why I wouldn't be in the same boat using a single DOS' ping.

Link to comment
Share on other sites

You can do it directly with Autoit:

HotKeySet("{ESC}", "Esc")
MsgBox(0,"","Press ESC to stop pinging")
Global $check = 0

While $check = 0
    $iPing = Ping("www.google.com", 250)
    If $iPing Then
        ConsoleWrite("The roundtrip-time took: " & $iPing & "ms." & @CRLF)
    Else
        Switch @error
            Case 1
                ConsoleWrite("ERROR: Host is offline" & @CRLF)
            Case 2
                ConsoleWrite("ERROR: Host is unreachable" & @CRLF)
            Case 3
                ConsoleWrite("ERROR: Bad destination" & @CRLF)
            Case 4
                ConsoleWrite("ERROR: Other errors" & @CRLF)
        EndSwitch
    EndIf
    Sleep(500)
WEnd

Func Esc()
    $check = 1
EndFunc
Link to comment
Share on other sites

Thank you for the example,Wayfarer.  If you run this script for more than about 5 minutes, do you get a few errors ("Host is offline") when using google.com as the host?  I do, running this script both from work and home (on different ISPs).  But I have a ping -t pinging google.com in a command prompt that has been running all morning with no dropped pings whatsoever.

The roundtrip-time took: 6ms.
The roundtrip-time took: 6ms.
ERROR: Host is offline
The roundtrip-time took: 7ms.
ERROR: Host is offline
The roundtrip-time took: 6ms.
The roundtrip-time took: 7ms.

Link to comment
Share on other sites

j0kky is right, I agree with him

you could try to increment the "timeout" parameter.

Take note that the default timeout is 4000 ms, while you are using just 250 ms

this could cause false timeouts with consequence of "false" responses of offline status.

I think that if the network where you are working has not very good performances or if the pinged device is not within your LAN (maybe also because your packet must flow through some routers or proxies that may downgrade overall performances) then you should calibrate the timeout parameter by increasing it's value till you will get plausible results from the ping.

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Thanks j0kky & Chimp!  I think j0kky is right too - I made some adjustments and already I'm seeing results that are much more in line with what I know to be true.  Thanks to everyone for their suggestions.  I will mark this issue solved.

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

×
×
  • Create New...