Sign in to follow this  
Followers 0
madmorgan

help with making pinger script

7 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by 99ojo

Share this post


Link to post
Share on other sites

i was so close but yet so far thanks for the help.

thanks

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

yea im from the uk i just have reaily bad reading and wirting and spelling probelms.

Share this post


Link to post
Share on other sites

#7 ·  Posted (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 by fardjad

Share this post


Link to post
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
Sign in to follow this  
Followers 0