Jump to content

Another Internet Monitor (ping based w/ tray status)


TRiCAM
 Share

Recommended Posts

I was searching the internet and the forums for an autoit based keep alive script for my internet as well as a way to have a small notification about it in the system tray. 
I couldn't find any so I went ahead and threw this together.  if anyone has any suggestions or comments i would love to hear them!
 
It works for me and i will include a link to a pre-compiled version if you want it:  thttp://tricamtech.com/script/NetStatus.exe
the ICO files are in that directory too. 
#Region 
#AutoIt3Wrapper_Icon=..\..\..\NetStatus\connected.ico
#AutoIt3Wrapper_Outfile=NetStatus.exe
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_Comment=Pings Google Public DNS  8.8.8.8
#AutoIt3Wrapper_Res_Description=Internet Ping Monitor
#AutoIt3Wrapper_Res_Fileversion=1.0
#AutoIt3Wrapper_Res_LegalCopyright=TRiCAM Tech Solutions
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_Res_Icon_Add=C:\NetStatus\connected.ico
#AutoIt3Wrapper_Res_Icon_Add=C:\NetStatus\disconnected.ico
#EndRegion 


Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode.
TraySetIcon(@ScriptFullPath, -6) ; Set the tray menu icon using the shell32.dll and the random index number.
sleep(3000) ;allow network to start up before running if on startup
status()

Func status()
   Local $iExit = TrayCreateItem("Exit")
   TraySetState(1) ; Show the tray menu.
   Local $hTimer = TimerInit() ; Begin the timer and store the handle in a variable.
   Local $iDiff = 0, $iIndex = 0

   Local $iPing1 = Ping("8.8.8.8", 1500)
;Run first time!
             If $iPing1 Then ;
                 icon('1', $iPing1)
             Else
                 icon('0', $iPing1)
             EndIf

  While 1
     $iDiff = TimerDiff($hTimer) ; Find the difference in time from the previous call of TimerInit
      Local $iPing = Ping("8.8.8.8", 1500)

        If $iDiff > 5000 Then ; If the difference is greater than 5 seconds then change the tray menu icon.

             If $iPing Then ;
                 icon('1', $iPing)
             Else
                 ;MsgBox(1, "", "You are Offline! Investigate!", 3000) If you want a notification.
                 icon('0', $iPing)
             EndIf
            $hTimer = TimerInit() ; Reset the timer.

     EndIf

        Switch TrayGetMsg()
            Case $iExit ; Exit the loop.
                ExitLoop
        EndSwitch
   WEnd
 EndFunc


Func icon($response, $pingtime)

    If $response = 1 Then
            TraySetToolTip("Connected - Time: " & $pingtime &"ms")
            TraySetIcon(@ScriptFullPath, -5)
           ; TraySetIcon("C:\Status\connected.ico") for use before compile 
         ElseIf $response = 0 Then
            TraySetToolTip("Disconnected - Error: " & $pingtime)
            TraySetIcon(@ScriptFullPath, -6)
            ;TraySetIcon("C:\Status\disconnected.ico") for use before compile 
           EndIf


EndFunc

Thanks guys!

TRiCAM

Edited by TRiCAM
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...