Jump to content

Recommended Posts

Hello,

I was looking around the net for a simple protable program to test whether you have an internet connection.. in short i couldnt find what i wanted so i wrote one.

After looking on the forum i found some code snippets from others who had started to this kind of thing, but no completed project.

Credits:

Autoit Team / Autoit Program!

ISN AutoIt Studio - '?do=embed' frameborder='0' data-embedContent>>

Post: '?do=embed' frameborder='0' data-embedContent>>

Autoitsnippet: http://www.autoitscript.com/wiki/AutoIt_Snippets#IsInternetConnected

Function (by Guiness): '?do=embed' frameborder='0' data-embedContent>>

I have attached the full code and compilied executable.

All constructive comments / improvement ideas / actual coded example imporovements, welcome.

Screenshots

Version 2

2014_03_09_20h57_22.png

2014_03_09_20h59_47.png

Version 1

2014_03_09_16h14_17.png

2014_03_09_16h14_24.png

2014_03_09_16h14_45.png

2014_03_09_16h14_48.png

Update:

09/03/2014 - v1.3 - Added a sleep() to the program loop to prevent high constant cpu usage - credit: wakillon

09/03/2014 - v1.2 - Added in another test (Microsoft Windows Test #2) using a function written by auto it forum member Guiness

09/03/2014 - v1.1 - Removed unnecessary includes, moved global variables to the top of the code - Credit: wakillon / water

Internet Connection Tester v1.3.zip

Edited by pilky1986
Link to comment
Share on other sites

A good script to check is >microsoftinternetconnectivity tester by Guinness.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Whoops, might help if i clicked upload :-)! thanks

 

Ok, tested and approved  :)

Remarks :

Only GUIConstantsEx.au3 is needed

It's more secure to declare your global variables at the start of the script.

What's the utility of : #include "FormsInternet_Connection_Tester.isf" ?  :huh:

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

ISF files are used by ISI360's >ISN AutoIt studio.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I think he just forgot to remove it.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Hello,

Thank you for the feedback.

You are quite right, i should of included the global variables before anything else, i have amended this. I forgot to remove the other #includes, they were in there because i was using them but in the end did not need them. I forgot to tidy that up!!

I will have a look at microsoftinternetconnectivity tester to see if i can integrate this into the program also as another test.

 

Finally with regards to "#include "FormsInternet_Connection_Tester.isf" as water says its part of ISN Autoit Studio, if you remove the include then your script wont compile as the related form/gui coding is not then included. I had a look over ISN Autoit Studio's example project and it appears to be the way the person has designed it to be included in peoples scripts, or at least that is what i have concluded. However, i may be wrong?

If there is a better way of doing this (? Fileinstall) then i shall happily go back and resolve and re-upload. Thanks :)

Link to comment
Share on other sites

Just noticed that when the program is running (idle, i.e. not testing) it runs at a constant CPU usage of 25%.. struggling to figure out why :unsure:, any thoughts?

2014_03_09_21h02_22.png

 

Add a sleep to your loop

Func _startgui()
    GUISetOnEvent($gui_event_close, "_ExitGUI", $internet_connection_tester)
    GUISetState(@SW_SHOW, $internet_connection_tester)
    While 1
        Switch GUIGetMsg()
            Case $gui_event_close
                ExitLoop
        EndSwitch
        Sleep ( 30 )
    WEnd
EndFunc
Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

 

Add a sleep to your loop

Func _startgui()
    GUISetOnEvent($gui_event_close, "_ExitGUI", $internet_connection_tester)
    GUISetState(@SW_SHOW, $internet_connection_tester)
    While 1
        Switch GUIGetMsg()
            Case $gui_event_close
                ExitLoop
        EndSwitch
        Sleep ( 30 )
    WEnd
EndFunc

 

How obvious! Thanks :-)

Its been a while since i used autoit, getting back into the swing of things now.

Link to comment
Share on other sites

i have made some simplifications

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Icon.ico
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseUpx=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

;##############################################################################################################################################
;# Project Name: Internet Connection Tester
;#
;# Author: Alex Pilkington
;# Email: alex.pilkington@nhs.net
;#
;# Version: 1.0
;# Creation Date: 09/03/2014
;#
;# Change Log (Version - Date - Comments):
;#
;# v1.0 - 09/03/2014 - Program Created
;#
;##############################################################################################################################################
;##############################################################################################################################################
;###################################################### INITIAL PROGRAM CODING ################################################################
;##############################################################################################################################################
;Include any AUTOIT pre-existing functions/parameters that are called in the program

#Region    ;************ Includes ************
#Include <GUIConstantsEx.au3>
#EndRegion ;************ Includes ************

Opt("TrayIconHide", 1)
Opt("GUIOnEventMode", 1)

Global $result_winintcontest, $colour_winintcontest
Global $result_googledns, $colour_googledns
Global $result_opendns, $colour_opendns
Global $result_googlewww, $colour_googlewww
Global $colour_blue = "0x0000FF"
Global $colour_green = "0x008000"
Global $colour_red = "0xFF0000"

$internet_connection_tester = GUICreate("", 316, 430, -1, -1, -1, -1)
GUICtrlCreateLabel("Internet Connection Tester", 10, 18, 295, 26, 1, -1)
GUICtrlSetFont(-1, 14, 400, 4, "Arial Rounded MT Bold")
GUICtrlSetBkColor(-1, "-2")
$clicktotest = GUICtrlCreateButton("Click To Test", 110, 350, 100, 30, -1, -1)
GUICtrlSetOnEvent(-1, "_ClickToTest")
GUICtrlCreateGroup("", 10, 50, 295, 344, -1, -1)
GUICtrlSetBkColor(-1, "0xF0F0F0")
GUICtrlCreateLabel("Written by: Alex Pilkington  -  Version: 1.0", 10, 404, 238, 15, -1, -1)
GUICtrlSetBkColor(-1, "-2")
GUICtrlCreateGroup("Google DNS", 30, 124, 254, 45, -1, -1)
GUICtrlSetFont(-1, 10, 700, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, "0xF0F0F0")
GUICtrlCreateGroup("Open DNS", 30, 180, 254, 45, -1, -1)
GUICtrlSetFont(-1, 10, 700, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, "0xF0F0F0")
GUICtrlCreateGroup("Google Website", 30, 236, 254, 45, -1, -1)
GUICtrlSetFont(-1, 10, 700, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, "0xF0F0F0")
$mwt = GUICtrlCreateLabel("NOT TESTED", 39, 88, 245, 29, 512, -1)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, "0x0000FF")
GUICtrlSetBkColor(-1, "-2")
GUICtrlCreateGroup("Microsoft Windows Test", 30, 72, 254, 45, -1, -1)
GUICtrlSetFont(-1, 10, 700, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, "0xF0F0F0")
$gdns = GUICtrlCreateLabel("NOT TESTED", 39, 140, 245, 26, 512, -1)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, "0x0000FF")
GUICtrlSetBkColor(-1, "-2")
$odns = GUICtrlCreateLabel("NOT TESTED", 39, 196, 245, 29, 512, -1)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, "0x0000FF")
GUICtrlSetBkColor(-1, "-2")
GUICtrlCreateGroup("Last Test", 30, 295, 254, 45, -1, -1)
GUICtrlSetFont(-1, 10, 700, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, "0xF0F0F0")
$gwww = GUICtrlCreateLabel("NOT TESTED", 39, 253, 245, 27, 512, -1)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, "0x0000FF")
GUICtrlSetBkColor(-1, "-2")
$lt = GUICtrlCreateLabel("N/A", 39, 309, 245, 31, 512, -1)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, "0x0000FF")
GUICtrlSetBkColor(-1, "-2")
GUISetOnEvent($gui_event_close, "_ExitGUI", $internet_connection_tester)
GUISetState(@SW_SHOW, $internet_connection_tester)

While 1
    Sleep ( 30 )
WEnd

Func _exitgui()
    GUIDelete($internet_connection_tester)
    Exit
EndFunc

Func _isinternetconnected()
    Local $areturn = DllCall("connect.dll", "long", "IsInternetConnected")
    If @error Then Return SetError(1, 0, True)
    Return $areturn[0] = 0
EndFunc

Func _pinggoogledns()
    Local $iping = Ping("8.8.8.8")
    If $iping > 0 Then
        $result_googledns = "SUCCESS"
        $colour_googledns = $colour_green
    Else
        $result_googledns = "FAILURE"
        $colour_googledns = $colour_red
    EndIf
EndFunc

Func _pingopendns()
    Local $iping = Ping("208.67.222.222")
    If $iping > 0 Then
        $result_opendns = "SUCCESS"
        $colour_opendns = $colour_green
    Else
        $result_opendns = "FAILURE"
        $colour_opendns = $colour_red
    EndIf
EndFunc

Func _pinggooglewww()
    Local $iping = Ping("www.google.co.uk")
    If $iping > 0 Then
        $result_googlewww = "SUCCESS"
        $colour_googlewww = $colour_green
    Else
        $result_googlewww = "FAILURE"
        $colour_googlewww = $colour_red
    EndIf
EndFunc

Func _clicktotest()
    GUICtrlSetBkColor($clicktotest, 16763904)
    GUICtrlSetData($clicktotest, "Testing...")
    $result_winintcontest = "Error - Not Tested"
    $result_googledns = "Error - Not Tested"
    $result_opendns = "Error - Not Tested"
    $result_googlewww = "Error - Not Tested"
    GUICtrlSetData($mwt, "Testing...")
    GUICtrlSetColor($mwt, $colour_blue)
    GUICtrlSetFont($mwt, 10, 400)
    Local $inc_result = _isinternetconnected()
    If $inc_result = "True" Then
        $result_winintcontest = "CONNECTED"
        $colour_winintcontest = $colour_green
    Else
        $result_winintcontest = "NOT CONNECTED"
        $colour_winintcontest = $colour_red
    EndIf
    GUICtrlSetData($mwt, $result_winintcontest)
    GUICtrlSetColor($mwt, $colour_winintcontest)
    GUICtrlSetFont($mwt, 10, 700)
    GUICtrlSetData($gdns, "Testing...")
    GUICtrlSetColor($gdns, $colour_blue)
    GUICtrlSetFont($gdns, 10, 400)
    _pinggoogledns()
    GUICtrlSetData($gdns, $result_googledns)
    GUICtrlSetColor($gdns, $colour_googledns)
    GUICtrlSetFont($gdns, 10, 700)
    GUICtrlSetData($odns, "Testing...")
    GUICtrlSetColor($odns, $colour_blue)
    GUICtrlSetFont($odns, 10, 400)
    _pingopendns()
    GUICtrlSetData($odns, $result_opendns)
    GUICtrlSetColor($odns, $colour_opendns)
    GUICtrlSetFont($odns, 10, 700)
    GUICtrlSetData($gwww, "Testing...")
    GUICtrlSetColor($gwww, $colour_blue)
    GUICtrlSetFont($gwww, 10, 400)
    _pinggooglewww()
    GUICtrlSetData($gwww, $result_googlewww)
    GUICtrlSetColor($gwww, $colour_googlewww)
    GUICtrlSetFont($gwww, 10, 700)
    GUICtrlSetData($lt, @MDAY & "/" & @MON & "/" & @YEAR & " at " & @HOUR & ":" & @MIN & ":" & @SEC)
    GUICtrlSetFont($lt, 10, 700)
    GUICtrlSetData($clicktotest, "Click To Test")
    GUICtrlSetStyle($clicktotest, 0)
EndFunc

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

Here's another way.......

 

TechCoder:

Func _online_status()
    Local $status = 0
    If @IPAddress1 <> "127.0.0.1" Then
        Local $oIE = _IECreate("http://www.msftncsi.com/ncsi.txt", 0, 0, 1, 0)
        Local $sText = _IEBodyReadText($oIE)
        If $sText = "Microsoft NCSI" Then
            $status = 1
        EndIf
        _IEQuit($oIE)
    EndIf
    Return $status
EndFunc   ;==>_online_status

I like that TechCoder, its a simplified way of doing what Guiness has done (which is the "Microsoft Windows Test #2", in my script). Nice code! :thumbsup:

Edited by pilky1986
Link to comment
Share on other sites

Does any one use a VPN here?

I do, and "Microsoft Windows Test #1" always fails when on the VPN (works if not) and the other test are successful, i assume its a limitation of the windows dll function call....

If someone could kindly verify if "Microsoft Windows Test #1" also fails on a VPN that would be greatly appreciated! :thumbsup:

Link to comment
Share on other sites

May be 'simplified', however, as stated in that post, my 'vote' is for the way guiness presented it - reads the dll the same as MS products - i.e., doesn't consume more resources and is 'equivalent' for many purposes.

When I get some time I'm going to study your multi-methods a bit more for one project I have (my program is faster than MS and works great for special purposes) and see if there is some 'combo' that makes for a better fit, though, lacking additional tests, I would say that a choice between the dll method and the 'fast' one that mirrors what Windows does (only with your own timer) seems to be the best.

Oh, on the VPN - sorry, can't help you, but I understand/feel that pain - being behind a router that is still running, but no internet connection is what caused me to research and get that function going.

BTW, I posted on this as I like your GUI idea (though would like to see it smaller - like 150 px high or something - would make a neat horizontal or vertical 'light' bar maybe?)

Link to comment
Share on other sites

May be 'simplified', however, as stated in that post, my 'vote' is for the way guiness presented it - reads the dll the same as MS products - i.e., doesn't consume more resources and is 'equivalent' for many purposes.

When I get some time I'm going to study your multi-methods a bit more for one project I have (my program is faster than MS and works great for special purposes) and see if there is some 'combo' that makes for a better fit, though, lacking additional tests, I would say that a choice between the dll method and the 'fast' one that mirrors what Windows does (only with your own timer) seems to be the best.

Oh, on the VPN - sorry, can't help you, but I understand/feel that pain - being behind a router that is still running, but no internet connection is what caused me to research and get that function going.

BTW, I posted on this as I like your GUI idea (though would like to see it smaller - like 150 px high or something - would make a neat horizontal or vertical 'light' bar maybe?)

 

I think most projects are driven out of necessity / curiosity. Like yourself, i have written this for a specific purpose, as i have a need to demonstrate to end users whether they have an internet connection. I built it in this way so that a user could run the app and test to see if they have an internet connection. As you said, they may have a LAN connection but not a WAN.

I like your thought about a smaller version, although personally i wouldn't have a need for it, so to be honest i doubt i would code a GUI for it :(

However, i think i could take this further by using a scoring method, based on each test to take away any interpretation required by the user. I think to be safe you would want to use a three-pronged approach to analysis which would require more tests than what is currently built in, probably pinging more DNS servers and potentially using more in-built windows functions, perhaps even checking TCP connections.

Depending on the outcome of further VPN testing, i will probably add in a message pop-up to notify the user that if test #1 fails and if they are on a VPN that this test is expected to fail (assuming the testing concludes this)

What was your project TechCoder?

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

×
×
  • Create New...