Jump to content

Check if internet is down script


Recommended Posts

Hi

I have made a small script for use on infoscreens on a school i work on, and i am a newbie into autoit scripting.

This is i want the script to do:

First check if internet is on the pc, if not then a splashimage is coming up that says internet is down. While the splashimage is up i want the script to check the whole time if the internet has returned and then close the splashimage, the rest is ok.

Here is the script

$ping = Ping ( "www.google.no" )
if @error Then
    SplashImageOn ( "infoskjerm", "C:/infoskjerm.JPG", @DesktopWidth,@DesktopHeight,0,0,1)
    
Else
    Do
        $ping = Ping ( "www.google.no" )
    Until Not @error
;Starter Firefox og maksimerer og gjør firefox fullskjerm
    SplashImageOn ( "infoskjerm", "C:/infoskjerm.JPG", @DesktopWidth,@DesktopHeight,0,0,1)
    run ("C:\Programfiler\Mozilla Firefox\firefox.exe" ,"", @SW_MAXIMIZE)
    WinActivate ( "show tilte browse - Mozilla Firefox" )
    WinWaitActive ("show tilte browse - Mozilla Firefox")
    Send ("{TAB} {F11}") 
    WinWait ("show tilte browse - Mozilla Firefox")
    MouseMove ( 1400, 980 )
EndIf

Can someone help me? :idea:

Link to comment
Share on other sites

Hey, do you want to use your code as a base?

I prefer working with functions, but you can incorporate it into the main program as well.

Here's something you can try:

It continuously checks for internet and if the connection is lost the splash is shown, once the connection returns the splash disappears.

The function returns 0 when there is no connection and returns the ping time otherwise.

$splashfile = "1.jpg"
$splashon = 0


while 1
    sleep(50)
    $internet = checkinternet()
    
    if $internet > 0 Then
        ;there is a connection
    EndIf
    
wend



func checkinternet()
    $res = Ping("www.google.no",2000)
    
    if $res = 0 and $splashon = 0 Then
            
            SplashImageOn("Infoscreen",$splashfile,@desktopwidth,@desktopheight,0,0,1)
            $splashon = 1
            
    ElseIf $res > 0 and $splashon = 1 then
            SplashOff()
            $splashon = 0
    EndIf
    
    return $res

EndFunc
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...