Draygoes

Simple Check For Internet (unfinished new bug found)

4 posts in this topic

#1 ·  Posted (edited)

EDIT: Warning...

Brewman said it the best: "Your last script will only tell you if your computer is connected to a network, it won't tell you if your network is connected to the internet." This was proven when my internet connection went out before I even got that warning and the script all to happily announced that I was connected. :mad:

Oh well... back to the drawing board. And this time I plan to test it during the night when I can reset my router whenever I need as a fair test of what happens during an outage.:(:sweating:

For now, it may still be of some use to others. I will leave the script below in tact even once the other version is completed because you never know. One mans trash and all that...

 

This is in general help and support as well, but I thought that it wouldnt hurt to post it here too.

There are plenty of reasons to check for an active connection, and this is a pretty different way of getting it done.

While 1
$connect = _GetNetworkConnect()

If $connect Then
    MsgBox(64, "YES!!!", $connect)
Exit
Else
    Sleep( 3000 )
EndIf
WEnd


Func _GetNetworkConnect()
    Local Const $NETWORK_ALIVE_LAN = 0x1  ;net card connection
    Local Const $NETWORK_ALIVE_WAN = 0x2  ;RAS (internet) connection
    Local Const $NETWORK_ALIVE_AOL = 0x4  ;AOL

    Local $aRet, $iResult

    $aRet = DllCall("sensapi.dll", "int", "IsNetworkAlive", "int*", 0)

    If BitAND($aRet[1], $NETWORK_ALIVE_LAN) Then $iResult &= "LAN connected" & @LF
    If BitAND($aRet[1], $NETWORK_ALIVE_WAN) Then $iResult &= "WAN connected" & @LF
    If BitAND($aRet[1], $NETWORK_ALIVE_AOL) Then $iResult &= "AOL connected" & @LF

    Return $iResult
EndFunc


And of course, I will give credit where it is due. I may have modified this code to my needs, but most of it belongs to rasim, and the original solution can be found here.

I truly hope that someone finds some use for this. :)

Edited by Draygoes

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 

Share this post


Link to post
Share on other sites



Thanks Draygoes - I will save this in my AutoIt achieves for later use. 

1 person likes this

Share this post


Link to post
Share on other sites

This won't tell you that you're connected to the internet, it only tells you if you have a network connection.

1 person likes this

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

This won't tell you that you're connected to the internet, it only tells you if you have a network connection.

As of this moment I will put a warning at the top of this thread until I can get a better version up and running. Thank you for pointing that out though, this could have caused serious headachs for developers.


Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 

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

  • Similar Content

    • Draygoes
      By Draygoes
      Please Note This Has Been Solved!
      I am leaving this here for anyone with the same problem. Solution in this post.
       
      Sorry for the vague title, but it was the best that I could come up with considering.
      Suddenlink has been switching our connection on and off for the last few days as they make upgrades. In some of these cases, its been a few hours. So, I decided to modify one of the example scripts in an attempt to get the script to display a msgbox upon finding an internet connection. I leave the volume on full, this way I know exactly when the connection comes back. The problem with this is that when I glanced at the computer after 30 more mins, I found that we DID have a connection, yet the script had not displayed the Msg. I do not feel that I need to tell you guys how out of touch with Autoit I am, so this is a problem that I cannot even fathom the issue of. In my mind, the script looks perfect. Anyway, I will defer to the wonderful genus that is this community to see what the issue is.
      I will upload the code as is. If you could present the fixed code, along with an explanation of what I did wrong I would be very grateful.
      Fix or not, I just thank you for taking the time to read this.
       
      #include <MsgBoxConstants.au3> Example() Func Example() Local $dData = InetRead("http://www.autoitscript.com/autoit3/files/beta/update.dat") Local $iBytesRead = @extended Local $sData = BinaryToString($dData) If $sData = "" Then Sleep( 1000 ) Example() EndIf MsgBox(0, "YAY!!!", "Internet Connection Back!") EndFunc As you can see, I was hoping that if it returned an empty string then the code would simply restart the function. But, should it show anything other than a blank string I figured that it would pass the EndIf and display the Msg. Somehow I got this wrong.
       
      I noticed one possible issue in the above code, and that was in the variable. I accidentally read the wrong variable it would seem. However, fixing that still did not result in a working script.


      EDITED CODE
      #include <MsgBoxConstants.au3> Example() Func Example() Local $dData = InetRead("http://www.autoitscript.com/autoit3/files/beta/update.dat") Local $iBytesRead = @extended Local $sData = BinaryToString($dData) If $dData = "" Then Sleep( 1000 ) Example() EndIf MsgBox(0, "YAY!!!", "Internet Connection Back!") EndFunc