Jump to content

Internet Ping Check help.


Recommended Posts

Hi, here i am again with a problem on a second script.

I am trying to make a script which pings several websites to check i am connected to the internet. If i am not connected to the internet it will then run a macro script to reset my internet. But for now i have made it pop up with a message because i don't want it to run the macro until i know it works. The program currently runs on a constant loop and checks every 30 minutes, so that is working well.

The reason i have 3 different websites is to make sure i am 100% connected incase any fail (i will be using all of my internet whilst it pings).

I have tried the script out whilst using my full download and so far the message box pops up, even though i know for sure that i am 100% connected.

I have tried swapping the "$ping > 0" to "$ping > 1" but the message box still pops up.

Here is my code, i think it has many many errors:

While 1
$ping = Ping("www.google.com")
If $ping > 0 then 
    $internet = True
    EndIf
$ping = Ping("www.yahoo.com")
If $ping > 0 Then
    $internet = True
    EndIf
$ping = Ping("www.bing.com")
If $ping > 0 Then
    $internet = True
    EndIf
If $ping > 1 Then
    $internet = False
    EndIf
If $internet = False Then
    msgBox (0, "internet", "internet not active")
EndIf
sleep(1800000)
WEnd

I have read somewhere that to ping multiple websites i must put the ping command inside an array and loop it? I am unsure how to do this, i don't even know where to start!

Thank you for reading

c4rv3r

Link to comment
Share on other sites

Hi, here i am again with a problem on a second script.

I am trying to make a script which pings several websites to check i am connected to the internet. If i am not connected to the internet it will then run a macro script to reset my internet. But for now i have made it pop up with a message because i don't want it to run the macro until i know it works. The program currently runs on a constant loop and checks every 30 minutes, so that is working well.

The reason i have 3 different websites is to make sure i am 100% connected incase any fail (i will be using all of my internet whilst it pings).

I have tried the script out whilst using my full download and so far the message box pops up, even though i know for sure that i am 100% connected.

I have tried swapping the "$ping > 0" to "$ping > 1" but the message box still pops up.

Here is my code, i think it has many many errors:

While 1
$ping = Ping("www.google.com")
If $ping > 0 then 
 $internet = True
    EndIf
$ping = Ping("www.yahoo.com")
If $ping > 0 Then
    $internet = True
    EndIf
$ping = Ping("www.bing.com")
If $ping > 0 Then
    $internet = True
    EndIf
If $ping > 1 Then
    $internet = False
    EndIf
If $internet = False Then
    msgBox (0, "internet", "internet not active")
EndIf
sleep(1800000)
WEnd

I have read somewhere that to ping multiple websites i must put the ping command inside an array and loop it? I am unsure how to do this, i don't even know where to start!

Thank you for reading

c4rv3r

You have

If $ping > 1 Then
    $internet = False
    EndIf

$ping will certainly be greater than 1 so why did you decide that meant there was no connection?

I think maybe you need to set $internet = False at the start of the while loop and miss out that test.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Ah, i understand the command a little better now, thank you. I was being thick thinking 0 was on and 1 was off and vice-versa.

I've got rid of the "ping > 1" and replaced it with ElseIf. Do you think this will work better?

While 1
$ping = Ping("www.google.com")
If $ping > 0 then 
    $internet = True
    EndIf
$ping = Ping("www.yahoo.com")
If $ping > 0 Then
    $internet = True
    EndIf
$ping = Ping("www.bing.com")
If $ping > 0 Then
    $internet = True
ElseIf $internet = False Then
    msgBox (0, "internet", "internet not active")
    EndIf
sleep(1800000)
WEnd
Link to comment
Share on other sites

AdlibRegister("_CheckConnection", 1800000) ;Call every 30 minutes

While 1
    Sleep(10)
WEnd

Func _CheckConnection()
    $TotalPing = Ping("www.google.com") + Ping("www.yahoo.com") + Ping("www.bing.com")
    If $TotalPing > 0 Then
        ;You are connected
    Else
        MsgBox(0, "Error", "You are not connected to the internet!", 5)
EndFunc

Edited by darkjohn20
Link to comment
Share on other sites

Heres my go

Global $bInternet = True

While 1
    If $bInternet Then
        Sleep(60000 * 30)
        _TestInternet()
    Else
        _MyMacro()
    EndIf
WEnd

Func _TestInternet()
    If Ping("www.google.com") > 0 Or Ping("www.yahoo.com") > 0 Or Ping("www.bing.com") > 0 Then
        Return True
    Else
        Return False
    EndIf
EndFunc   ;==>_TestInternet

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

@darkjohn20

@JohnOne

Looking at both of your versions makes me realise how in-superior my coding is! Excellent designs! Both scripts are fantastic. Thank you for your input, i am learning alot looking at your scripts. I am really enjoying AutoIt, its so capable, as capable as any other language!

CarVeR

Link to comment
Share on other sites

Glad you are happy, and dont forget there is more than one way to skin a cat.

you could add this test if you need to be super sure all three of those search engines arnt offline

#include <INet.au3>
If _INetGetSource("http://www.whatismyip.com/automation/n09230945.asp", True) Then
    MsgBox(64, "Yay", "Connected")
Else
    MsgBox(16, "Booo", "Not Connected")
EndIf

or

#include <INet.au3>
If _GetIP() Then
    MsgBox(64, "Yay", "Connected")
Else
    MsgBox(16, "Booo", "Not Connected")
EndIf

or both I suppose

Not in the above format of course, but you get the idea.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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