ttleser Posted February 22, 2007 Share Posted February 22, 2007 I created a simple script to monitor a internet connection. If the connection goes down it'll write a line to a .log file telling you when it went down. Once the connection is back up again it'll write another line to the same .log file telling you when it went back up. Being "down" is dependent on whether or not the ping to www.google.com is over 1000 milliseconds. I can test the script by changing the gateway on the test computer to something different than my home router. The problem I'm having is while the script is running it'll write lines to the log file telling me it's down and right up again while I HAVE NOT changed the gateway from the correct address. I will run "ping www.google.com -t" from a command line and it'll never go over 70ms. So, why is it that ping from a DOS prompt won't report a ping of over 70ms, but the autoit script will??? Here's the script: expandcollapse popup#include <GuiConstants.au3> #include <GuiListView.au3> #include<date.au3> #include <INet.au3> Global $Sec, $Min, $Hour, $Time1 ;$INETHop = IniRead("settings.ini", "Settings", "INETHop", "") $INETHop = "www.google.com" $INETDOWN = "" $INETUP = "" $INETDOWNBIT = "" $INETUPBIT = "" While 1 $date = StringReplace(_NowDate(),"/","-") $file = "INet "&$date&".log" $var2 = Ping($INETHop, 1000) If $var2 < 1 Then If $INETDOWNBIT = "" then $INETDOWNBIT = "1" Time1() FileWriteLine($file, "INET went down at: "& $Time1 & @CRLF) EndIf EndIf If $INETDOWNBIT = "1" then $var3 = Ping($INETHop, 1000) If $var3 > 0 then $INETUPBIT = "1" Time1() FileWriteLine($file, "INET came up at: "& $Time1 & @CRLF) $INETDown = "" $INETDOWNBIT = "" $INETUP = "" $INETUPBIT = "" ENDIF EndIf WEnd Func Time1() If @hour = "12" then $hour = @hour $ampm = "PM" ElseIf @hour >= "13" then $hour = @hour - 12 $ampm = "PM" ElseIf @hour < "12" then $hour = @hour $ampm = "AM" ElseIf @hour = 0 then $hour = 12 + @hour $ampm = "AM" EndIF $Time1 = ($hour&":"&@min&":"&@sec&" "&$ampm) EndFunc Link to comment Share on other sites More sharing options...
SadBunny Posted February 22, 2007 Share Posted February 22, 2007 So, why is it that ping from a DOS prompt won't report a ping of over 70ms, but the autoit script will???I haven't tried to reproduce, but I'm willing to bet that it is because you didn't include a Sleep() in your While 1 loop. The dos ping command doesn't wait a second between every ping for nothing... Retry using Sleep(1000) or something in the loop, probably better then. Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
ttleser Posted February 22, 2007 Author Share Posted February 22, 2007 Problem with adding a 1sec sleep to the script means that if the connection went down for less than 1 second then I might not find out about it. Just so you know it's meant for troubleshooting VPN connection issues, so even if the internet connection went down for less than a second the VPN connection will drop, which is bad news. I'm a little lost by >> The dos ping command doesn't wait a second between every ping for nothing... Retry using Sleep(1000) or something in the loop, probably better then. As I see it I don't want any wait between pings. Link to comment Share on other sites More sharing options...
SadBunny Posted February 22, 2007 Share Posted February 22, 2007 I'm a little lost by >> The dos ping command doesn't wait a second between every ping for nothing... Retry using Sleep(1000) or something in the loop, probably better then. As I see it I don't want any wait between pings. Now I DID try to reproduce... Got the same results as you did, a failed ping after some time.Doing too many pings after eachother will cause some pings to fail if too many connections are made during too little time. Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
ttleser Posted February 22, 2007 Author Share Posted February 22, 2007 ah, ok. Do you think 250 milliseconds would be ok? Link to comment Share on other sites More sharing options...
SadBunny Posted February 22, 2007 Share Posted February 22, 2007 ah, ok. Do you think 250 milliseconds would be ok?What I would do is assess what you expect your ping roundtrip time in ms to be on average, and Sleep()ing about that amount of ms in the script. So if your ping to Google averages 70 ms, I would Sleep(70), so it waits on average long enough to not DOS-attack yourself Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
ttleser Posted February 22, 2007 Author Share Posted February 22, 2007 I see. Thanks. Between posts I added a 250ms sleep to the script and it appears to have gotten better, haven't seen a entry in the file for a little while now. As an after-thought, is there a better way to monitor a connection besides ping? I'd be open to suggestions. Link to comment Share on other sites More sharing options...
SadBunny Posted February 23, 2007 Share Posted February 23, 2007 As an after-thought, is there a better way to monitor a connection besides ping? I'd be open to suggestions.I'm no protocol crack but if you want to monitor the internet connection of a remote system you need to exchange data with it in some form or another, like a ping. Maybe someone better at protocols knows something better, but what comes to my mind is instead of creating thousands of connections like you do now, keeping ONE connection open (like creating a listening port on your system, and making the remote system send a bit multiple times a second, and if your system receives nothing for some time, sound the alarm bells).Your general caveat is a per-definition tradeoff: the more bytes you send, the better the information, but the more bandwith is used. If you transmit with maximum bandwith, you will know immediately, but it will cost a lot of bandwith. You could do this for some time though if you want really thorough checking. Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
Shevilie Posted February 23, 2007 Share Posted February 23, 2007 I would be pissed if you pinged my server like that... Even if I was the creator of google... Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit Link to comment Share on other sites More sharing options...
SadBunny Posted February 23, 2007 Share Posted February 23, 2007 I would be pissed if you pinged my server like that... Even if I was the creator of google...Haha, right Thought crossed my mind. Luckily this remote system that he ACTUALLY wants to ping seems to be a server in his control That's why keeping ONE connection open and sending some bytes every now and then seems better... Unless there's already some function or something for this which I don't know of Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
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