Sign in to follow this  
Followers 0
Encryption

Detecting If Connected to The Internet

4 posts in this topic

Anybody have a code snippet that would check if they are connected to the internet? I am using this for a script I am making.

Thanks in advance.

~Mason

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

$HomeIP = _GetIP()
$TestInternet = Ping($HomeIP)

GUICreate("Day of Defeat Source - Sign In", 265, 100)
$UserNameLabel = GUICtrlCreateLabel("Username:", 5, 13, 60)
$UserName = GUICtrlCreateInput("", 60, 10, 200, 20)
$PasswordLabel = GUICtrlCreateLabel("Password:", 5, 37, 60)
$Password = GUICtrlCreateInput("", 60, 34, 200, 20)
$Button = GUICtrlCreateButton("OK", 100, 70, 80)
GUISetState (@SW_SHOW) 
While 1
    $msg = GUIGetMsg()
    
    If $msg = $Button Then
        If $TestInternet Then ExitLoop
        Else
            MsgBox(0, "Error", "You do not have an active internet connect.  Connect to the internet, then try again.")
    EndIf
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    
Wend

Apparently I am not doing something right there. It said I was not connected to the internet(I was) and it did not wait till I pressed $Button. Any help?

Edited by Encryption

Share this post


Link to post
Share on other sites

Ping returns 0 on error. If $TestInternet = 0 then not connected to Internet.

Try this:

#include <inet.au3>
#include <GUIConstants.au3>

$HomeIP = _GetIP()
$TestInternet = Ping($HomeIP)
MsgBox(262144,'debug line ~5' , '$TestInternet:' & @lf & $TestInternet);### Debug MSGBOX

GUICreate("Day of Defeat Source - Sign In", 265, 100)
$UserNameLabel = GUICtrlCreateLabel("Username:", 5, 13, 60)
$UserName = GUICtrlCreateInput("", 60, 10, 200, 20)
$PasswordLabel = GUICtrlCreateLabel("Password:", 5, 37, 60)
$Password = GUICtrlCreateInput("", 60, 34, 200, 20)
$Button = GUICtrlCreateButton("OK", 100, 70, 80)
GUISetState (@SW_SHOW) 

While 1
    $msg = GUIGetMsg()
    
    If $msg = $Button Then
        If $TestInternet = 0 Then
            MsgBox(0, "Error", "You do not have an active internet connect.  Connect to the internet, then try again.")
        Else
            MsgBox(0, 'Connected', 'Connection is good')
        EndIf
    EndIf
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    
Wend

Share this post


Link to post
Share on other sites

Thank you...here is my current code (I fixed it up to make it a bit prettier...but I think it works.)

GUICreate("Day of Defeat : Source - Sign In", 265, 100)
$UserNameLabel = GUICtrlCreateLabel("Username:", 5, 13, 60)
$UserName = GUICtrlCreateInput("", 60, 10, 200, 20)
$PasswordLabel = GUICtrlCreateLabel("Password:", 5, 37, 60)
$Password = GUICtrlCreateInput("", 60, 34, 200, 20)
$Button = GUICtrlCreateButton("OK", 100, 70, 80)
GUISetState (@SW_SHOW) 
While 1
    $msg = GUIGetMsg()
    if $msg = $GUI_EVENT_CLOSE Then ExitLoop
    Select
        
        Case $msg = $Button 
            $HomeIP = _GetIP()
            $TestInternet = Ping($HomeIP, 1000)
            If $TestInternet > 0 Then 
            ExitLoop
            Else 
            MsgBox(0, "Error", "You do not have an active internet connection.  Connect to the internet, then try again.")
            EndIf
        
        
    EndSelect
Wend

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
Sign in to follow this  
Followers 0