Encryption Posted February 7, 2005 Posted February 7, 2005 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
Encryption Posted February 7, 2005 Author Posted February 7, 2005 (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 February 7, 2005 by Encryption
MHz Posted February 7, 2005 Posted February 7, 2005 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
Encryption Posted February 7, 2005 Author Posted February 7, 2005 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now