Jump to content

Detecting If Connected to The Internet


Recommended Posts

$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
Link to comment
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
Link to comment
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
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...