madmorgan Posted March 15, 2010 Share Posted March 15, 2010 hello all, i suffer from reaily bad net were i live. im trying to build a script that stays alive, so then the program starts in the morring it writes to a file saying net online and as soon as it drops off it writes to the same file again saying off line. But i also want to keep looking for the netagain after it has droped off so it then can reedit the file at put online at this time. sorry if this is all over the place. here is what i have come up with. #include <Date.au3> $date = _DateTimeFormat( _NowCalc(),1) $file = 0 $info = (", "&$date&" "&"AT: "&@HOUR&","&@MIN) $var = Ping("www.google.co.uk",250) If @error = 0 Then $text = ("Online, roundtrip was: "&$var&$info&@CRLF) write() Else $text = ("**************** OFFLINE, Connection Lost "&$info&"***********************"&@CRLF) write() EndIf While 1 WEnd Func write() $file = ("\\192.168.0.2\usb1\Resuilts.txt") FileOpen($file,1) FileWrite ($file, $text) FileClose($file) EndFunc Link to comment Share on other sites More sharing options...
99ojo Posted March 15, 2010 Share Posted March 15, 2010 (edited) Hi, just think about, where your code is running: Once written to your file and then running in your while loop -> nothing happens there. So just put your statment for checking the inet in your while loop: While 1 $var = Ping("www.google.co.uk",250) If @error = 0 Then write("Online, roundtrip was: "&$var&" ms "&@MDAY&"."&@MON&"."&@YEAR&" "&@HOUR&":"&@MIN&":"&@SEC&@CRLF) Else write("**************** OFFLINE, Connection Lost "&@MDAY&"."&@MON&"."&@YEAR&" "&@HOUR&":"&@MIN&":"&@SEC&"***********************"&@CRLF) EndIf ;sleep 1 min and check again, change if you want to Sleep (60000) WEnd Func write($text) $file = ("\\192.168.0.2\usb1\Resuilts.txt") FileOpen($file,1) FileWrite ($file, $text) FileClose($file) EndFunc I also change your function write; and $info is 'built' with autoit macro variables. ;-)) Stefan Edited March 15, 2010 by 99ojo Link to comment Share on other sites More sharing options...
madmorgan Posted March 15, 2010 Author Share Posted March 15, 2010 i was so close but yet so far thanks for the help. thanks Link to comment Share on other sites More sharing options...
madmorgan Posted March 15, 2010 Author Share Posted March 15, 2010 ah ok one more question please that works geate how can i change it so that it dones not write every min. it only wites if the connection is there when it fist starts and then records if and then writes if it dorops or it writes again once it has come back. Link to comment Share on other sites More sharing options...
Developers Jos Posted March 15, 2010 Developers Share Posted March 15, 2010 ah ok one more question please that works geate how can i change it so that it dones not write every min. it only wites if the connection is there when it fist starts and then records if and then writes if it dorops or it writes again once it has come back.you are sure you are from the UK? SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
madmorgan Posted March 15, 2010 Author Share Posted March 15, 2010 yea im from the uk i just have reaily bad reading and wirting and spelling probelms. Link to comment Share on other sites More sharing options...
fardjad Posted March 15, 2010 Share Posted March 15, 2010 (edited) ah ok one more question please that works geate how can i change it so that it dones not write every min. it only wites if the connection is there when it fist starts and then records if and then writes if it dorops or it writes again once it has come back. hope this helps : dim $LastState $var = Ping("www.google.co.uk",250) If @error = 0 Then $LastState = 0; write("Online, roundtrip was: "&$var&" ms "&@MDAY&"."&@MON&"."&@YEAR&" "&@HOUR&":"&@MIN&":"&@SEC&@CRLF) Else $LastState = 1; write("**************** OFFLINE, Connection Lost "&@MDAY&"."&@MON&"."&@YEAR&" "&@HOUR&":"&@MIN&":"&@SEC&"***********************"&@CRLF) EndIf While 1 $var = Ping("www.google.co.uk",250) if ( not @error = $LastState ) Then If @error = 0 Then $LastState = 0; write("Online, roundtrip was: "&$var&" ms "&@MDAY&"."&@MON&"."&@YEAR&" "&@HOUR&":"&@MIN&":"&@SEC&@CRLF) Else $LastState = 1; write("**************** OFFLINE, Connection Lost "&@MDAY&"."&@MON&"."&@YEAR&" "&@HOUR&":"&@MIN&":"&@SEC&"***********************"&@CRLF) EndIf EndIf ;sleep 1 min and check again, change if you want to Sleep (60000) WEnd Func write($text) $file = ("\\192.168.0.2\usb1\Resuilts.txt") FileOpen($file,1) FileWrite ($file, $text) FileClose($file) EndFunc Update: you can remove Sleep (60000) to make the script log the changes promptly. Edited March 15, 2010 by fardjad 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