PDA

View Full Version : Check internet connection



ErosOlmi
18-03-2007, 09:23
This thinBasic script will:

tell you your LAN IPs
check if internet connection is active
if not active will try to connect using standard RAS dialog
info on connection


Attention:
in case you have some firewall installed (mainly personal firewalls like ZoneAlarm) you will get a warning about thinBasic trying to connect to internet.
This is normal and right because this script will attemp to do so in order to check internet connection.



'---Description : Check Internet Connection

Uses "INet" '---Load INet module
Uses "RAS" '---Load RAS module

'--------------------------------------------------------------------------
'Check if connection to internet is active
'If not active standard connection dialog box is started
'--------------------------------------------------------------------------
FUNCTION RunConnectToInternet() AS LONG
'--------------------------------------------------------------------------
DIM IConnected AS LONG
DIM Message AS STRING

FUNCTION = TRUE

'--- Check current connection status
IConnected = INET_GETSTATE

'---
'If already connected then use current connection
'otherwise try to make a connection
'---
IF IConnected = FALSE THEN
'-If not connected, try to run AutoDialing windows functionality
RAS_OPENDIALUPDIALOG
'-Check again connection
IConnected = INET_GETSTATE
'-If not connect again, error message
IF IConnected = FALSE THEN
Message = "It was not possible to connect to Internet.\n\n"
MSGBOX(0, Message,"OKONLY EXCLAMATION","Error During Internet Connection.")
FUNCTION = FALSE
END IF
END IF

END FUNCTION

FUNCTION DecodeConnectionMode(iMode AS LONG) AS STRING
DIM sMode AS STRING

IF iMode AND %INTERNET_CONNECTION_MODEM THEN sMode += "Modem" & $CRLF
IF iMode AND %INTERNET_CONNECTION_LAN THEN sMode += "Lan" & $CRLF
IF iMode AND %INTERNET_CONNECTION_PROXY THEN sMode += "Proxy" & $CRLF
IF iMode AND %INTERNET_CONNECTION_MODEM_BUSY THEN sMode += "ModemBusy" & $CRLF
IF iMode AND %INTERNET_RAS_INSTALLED THEN sMode += "RasInstalled" & $CRLF
IF iMode AND %INTERNET_CONNECTION_OFFLINE THEN sMode += "ConnectionOffLine" & $CRLF
IF iMode AND %INTERNET_CONNECTION_CONFIGURED THEN sMode += "ConnectionConfigured" & $CRLF

FUNCTION = sMode

END FUNCTION

'----------------------------------------------------------------------
'Main program
'----------------------------------------------------------------------
DIM Msg AS STRING
DIM IPCount AS LONG
DIM iMode AS LONG

IF RunConnectToInternet() = TRUE THEN
iMode = INET_GetConnectionMode
Msg = "You are connected to Internet." + $CRLF + _
"Your currect connection mode is: " + iMode + $CRLF + _
"Mode " & iMode & " means: " & $crlf & DecodeConnectionMode(iMOde) & $CRLF
ELSE
Msg = "You are NOT connected to Internet." + $CRLF
END IF

Msg += "You have " + INET_GETIP(0) + " IPs on your box." + $CRLF

IF INET_GETIP(0) > 1 THEN
Msg += "They are:" + $CRLF
ELSE
Msg += "It is:" + $CRLF
END IF

FOR IPCount = 1 TO INET_GETIP(0)
Msg += INET_GETIP(IPCount) + $CRLF
NEXT
MSGBOX(0, Msg)

Michael Hartlef
18-03-2007, 09:55
Thanks, what is the difference between this and the sample inside the INET folder?

ErosOlmi
18-03-2007, 10:07
They are the same.
I'm posting in this area as source code in order to show people surfing this web about thinBasic possibilities and mainly about thinBasic easy syntax and easy implementing complex tasks with few lines of code.

matthew
18-03-2007, 10:42
That's a useful Example. :)

Lee Allen
21-03-2007, 02:49
Thats a great example of the way ThinBasic can do complex tasks with a simple script.

I learn much faster from examples like this than reading dry documentation. I was attracted in the
first place to ThinBasic by the wealth of Sample Scripts. One simple example is worth dozens
of pages of explanation (I wish M$ would learn that!)

Im only a short way into ThinBasic but I am beginning to see this language has great potential. I learn something new every day and have not been disappointed.

kryton9
21-03-2007, 03:58
Lee the way you put it is the way it is. Once you find an area to focus on, or pick a programming project for yourself, then you get hooked to the wonders of thinBasic. As you try to put your program together and go through the help and scan the modules and see the commands, and then find the samples both in the help and on the forums. Things start clicking and you get hooked and more project ideas come to mind.

As you saw this week, we wanted a few special commands and boom they were done and ready to use. Glad you are enjoying it and am sure you will continue to for a long time!!

Lee Allen
21-03-2007, 13:52
Thanks Kryton - I think I am already hooked :)

kryton9
22-03-2007, 05:37
That's great Lee!!