MuffinMan Posted August 4, 2014 Posted August 4, 2014 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? expandcollapse popupIf $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
PainTain Posted August 4, 2014 Posted August 4, 2014 You could just use run ping in a command prompt in the background, read the output and parse it.
MuffinMan Posted August 4, 2014 Author Posted August 4, 2014 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.
computergroove Posted August 5, 2014 Posted August 5, 2014 Read STDOutRead -> https://www.autoitscript.com/autoit3/docs/functions/StdoutRead.htm Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html
MuffinMan Posted August 5, 2014 Author Posted August 5, 2014 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.
j0kky Posted August 5, 2014 Posted August 5, 2014 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 Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs
MuffinMan Posted August 5, 2014 Author Posted August 5, 2014 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.
Solution j0kky Posted August 5, 2014 Solution Posted August 5, 2014 have you set the same timeout for Autoit Ping and Dos Ping? MuffinMan 1 Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs
Gianni Posted August 5, 2014 Posted August 5, 2014 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. Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
MuffinMan Posted August 5, 2014 Author Posted August 5, 2014 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.
j0kky Posted August 5, 2014 Posted August 5, 2014 Glad to have helped you Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs
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