Results 1 to 8 of 8

Thread: Check internet connection

  1. #1
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,795
    Rep Power
    10

    Check internet connection

    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.

    [code=thinbasic]
    '---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)
    [/code]
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  2. #2

    Re: Check internet connection

    Thanks, what is the difference between this and the sample inside the INET folder?

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,795
    Rep Power
    10

    Re: Check internet connection

    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.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  4. #4

    Re: Check internet connection

    That's a useful Example.
    Operating System: Windows 10 Home 64-bit
    CPU: Intel Celeron N4000 CPU @ 1.10GHz
    Memory: 4.00GB RAM
    Graphics: Intel UHD Graphics 600

  5. #5

    Re: Check internet connection

    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.


  6. #6
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    68
    Posts
    3,869
    Rep Power
    404

    Re: Check internet connection

    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!!
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  7. #7

    Re: Check internet connection

    Thanks Kryton - I think I am already hooked

  8. #8
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    68
    Posts
    3,869
    Rep Power
    404

    Re: Check internet connection

    That's great Lee!!
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

Similar Threads

  1. Do you need to check internet connection?
    By ErosOlmi in forum Sources, Templates, Code Snippets, Tips and Tricks, Do you know ...
    Replies: 0
    Last Post: 16-10-2006, 10:45

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •