Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to find if a machine is having internet connection.

How to find if a machine is having internet connection.

Scheduled Pinned Locked Moved C / C++ / MFC
jsontutorial
11 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R RuchirD

    Hi I am writing an application which needs to know if the user is having internet connection enabled or not. I want this checking to be done automatically by the application, I donot want to pop up connect internet dialog. Can anyone tell me if there is any API/function to findout that the machine is having internet connection. Regards, Ruchirdhar Dwivedi RuchirDhar Dwivedi Software Engineer Windowmaker Software Pvt.Ltd. Baroda, India.

    T Offline
    T Offline
    ThatsAlok
    wrote on last edited by
    #2

    mr ruchir use his api InternetGetConnectedState

    This function retrieves the connected state of the local system.

    BOOL InternetGetConnectedState(
    LPDWORD lpdwFlags,
    DWORD dwReserved);


    "I Think this Will Help"

    visit me at http://www.thisisalok.tk
    R 1 Reply Last reply
    0
    • T ThatsAlok

      mr ruchir use his api InternetGetConnectedState

      This function retrieves the connected state of the local system.

      BOOL InternetGetConnectedState(
      LPDWORD lpdwFlags,
      DWORD dwReserved);


      "I Think this Will Help"

      visit me at http://www.thisisalok.tk
      R Offline
      R Offline
      Ryan Binns
      wrote on last edited by
      #3

      InternetGetConnectedState() only works for modem connections. It will return FALSE even if the user is connected via a network. The only truly correct method of knowing is by actually trying to connect to a known website. If it works, then you're connected. If it doesn't work, then you're probably not connected (not definitely - the website might be down).

      Ryan

      "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

      T R 2 Replies Last reply
      0
      • R Ryan Binns

        InternetGetConnectedState() only works for modem connections. It will return FALSE even if the user is connected via a network. The only truly correct method of knowing is by actually trying to connect to a known website. If it works, then you're connected. If it doesn't work, then you're probably not connected (not definitely - the website might be down).

        Ryan

        "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

        T Offline
        T Offline
        ThatsAlok
        wrote on last edited by
        #4

        small question Sir!, then what is meaning of INTERNET_CONNECTION_LAN in above api thanks


        "I Think this Will Help"

        visit me at http://www.thisisalok.tk
        1 Reply Last reply
        0
        • R Ryan Binns

          InternetGetConnectedState() only works for modem connections. It will return FALSE even if the user is connected via a network. The only truly correct method of knowing is by actually trying to connect to a known website. If it works, then you're connected. If it doesn't work, then you're probably not connected (not definitely - the website might be down).

          Ryan

          "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

          R Offline
          R Offline
          RuchirD
          wrote on last edited by
          #5

          Hey I was just searching on the MSDN and I got something WinInet API's in which there is function InternetOpen(...) will it help me?? I mean just checking handle (if null then no internet, if not null internet available.) Do anyone has any idea about this WinInet API and tell me whether it will help me?? Regards. RuchirDhar Dwivedi. RuchirDhar Dwivedi Software Engineer Windowmaker Software Pvt.Ltd. Baroda, India.

          T 1 Reply Last reply
          0
          • R RuchirD

            Hey I was just searching on the MSDN and I got something WinInet API's in which there is function InternetOpen(...) will it help me?? I mean just checking handle (if null then no internet, if not null internet available.) Do anyone has any idea about this WinInet API and tell me whether it will help me?? Regards. RuchirDhar Dwivedi. RuchirDhar Dwivedi Software Engineer Windowmaker Software Pvt.Ltd. Baroda, India.

            T Offline
            T Offline
            ThatsAlok
            wrote on last edited by
            #6

            RuchirD wrote: function InternetOpen(...) will it help me?? i don't think soo,as msdn state that "This function initializes an application’s use of the Windows CE Internet functions." the equivalent function for windows is InternetOpenUrl().


            "I Think this Will Help"

            visit me at http://www.thisisalok.tk
            R 1 Reply Last reply
            0
            • T ThatsAlok

              RuchirD wrote: function InternetOpen(...) will it help me?? i don't think soo,as msdn state that "This function initializes an application’s use of the Windows CE Internet functions." the equivalent function for windows is InternetOpenUrl().


              "I Think this Will Help"

              visit me at http://www.thisisalok.tk
              R Offline
              R Offline
              RuchirD
              wrote on last edited by
              #7

              This function initializes an application’s use of the Windows CE Internet functions." I think there is some confusion. Windows function call InternetOpenURL uses Handle that is returned by the function call InternetOprn(...) Pls see below InternetOpenUrl Opens a resource specified by a complete FTP, Gopher, or HTTP URL. HINTERNET InternetOpenUrl( HINTERNET hInternet, LPCTSTR lpszUrl, LPCTSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext ); Parameters hInternet [in] Handle to the current Internet session. The handle must have been returned by a previous call to InternetOpen Plz correct me if I am wrong. What I could conclude from the MSDN excerpt is that "InternetOpen returns handle to the internet session if connected and if not it will return null, using this handle we can open an URL using InternetOpenURL() function". Also the exact use case is "check if user is connected to the internet". Thanks n Regards RuchirDhar Dwivedi. RuchirDhar Dwivedi Software Engineer Windowmaker Software Pvt.Ltd. Baroda, India.

              T 1 Reply Last reply
              0
              • R RuchirD

                This function initializes an application’s use of the Windows CE Internet functions." I think there is some confusion. Windows function call InternetOpenURL uses Handle that is returned by the function call InternetOprn(...) Pls see below InternetOpenUrl Opens a resource specified by a complete FTP, Gopher, or HTTP URL. HINTERNET InternetOpenUrl( HINTERNET hInternet, LPCTSTR lpszUrl, LPCTSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext ); Parameters hInternet [in] Handle to the current Internet session. The handle must have been returned by a previous call to InternetOpen Plz correct me if I am wrong. What I could conclude from the MSDN excerpt is that "InternetOpen returns handle to the internet session if connected and if not it will return null, using this handle we can open an URL using InternetOpenURL() function". Also the exact use case is "check if user is connected to the internet". Thanks n Regards RuchirDhar Dwivedi. RuchirDhar Dwivedi Software Engineer Windowmaker Software Pvt.Ltd. Baroda, India.

                T Offline
                T Offline
                ThatsAlok
                wrote on last edited by
                #8

                RuchirD wrote: Windows function call InternetOpenURL uses Handle that is returned by the function call InternetOprn(...) Yeah you are RIght!,Sorry i Interpreted it wrong. RuchirD wrote: What I could conclude from the MSDN excerpt is that "InternetOpen returns handle to the internet session if connected and if not it will return null, using this handle we can open an URL using InternetOpenURL() function". InternetOpen according to MSDN "InternetOpen is the first Win32 Internet function called by an application. It tells the Internet DLL to initialize internal data structures and prepare for future calls from the application." So it just Initializing the Local Variable ONly , not checking the State of Internet.i.e. you can simulate the use of Internet api using LOCAL WebServer. But InternetGetConnectedState return with actual Internet State. TRY IT!


                "I Think this Will Help"

                visit me at http://www.thisisalok.tk
                R 1 Reply Last reply
                0
                • T ThatsAlok

                  RuchirD wrote: Windows function call InternetOpenURL uses Handle that is returned by the function call InternetOprn(...) Yeah you are RIght!,Sorry i Interpreted it wrong. RuchirD wrote: What I could conclude from the MSDN excerpt is that "InternetOpen returns handle to the internet session if connected and if not it will return null, using this handle we can open an URL using InternetOpenURL() function". InternetOpen according to MSDN "InternetOpen is the first Win32 Internet function called by an application. It tells the Internet DLL to initialize internal data structures and prepare for future calls from the application." So it just Initializing the Local Variable ONly , not checking the State of Internet.i.e. you can simulate the use of Internet api using LOCAL WebServer. But InternetGetConnectedState return with actual Internet State. TRY IT!


                  "I Think this Will Help"

                  visit me at http://www.thisisalok.tk
                  R Offline
                  R Offline
                  RuchirD
                  wrote on last edited by
                  #9

                  Hi Thanks for information. I m Still having some doubt and some confusion. Coming to doubt:- I want to know whether user is connected to the internet it should not be application's concern that user is connected to the internet via LAN/PROXY/DIALUP. How to do that?? (connected to internet means connection is esatblished not just that internet is configured.) Coming to Confusion:- As you said that the InternetOpen according to MSDN "InternetOpen is the first Win32 Internet function called by an application. It tells the Internet DLL to initialize internal data structures and prepare for future calls from the application." but in the description of InternetOpen they say InternetOpen For a general utility or application, you should start with the InternetOpen function. By specifying the Internet agent you want to do the Internet access (for example, Microsoft Internet Explorer), the type of access you want, and a few optional flags, this function returns you a handle to an Internet session. When you are finished with the connection, you must close it by passing the handle to the InternetCloseHandle function. For example: HINTERNET hInternetSession; hInternetSession = InternetOpen( "Microsoft Internet Explorer", // agent INTERNET_OPEN_TYPE_PRECONFIG, // access NULL, NULL, 0); // defaults . . . InternetCloseHandle(hInternetSession); This will make a connection to the Internet, using the Internet agent "Microsoft Internet Explorer," and return a handle to the connection, if successful. By specifying the parameter INTERNET_OPEN_TYPE_PRECONFIG, you have requested the agent to use certain values that are stored in the registry. The rest of the parameters are set to use the default configurations. In one simple call, you have made a connection to the Internet—assuming nothing went wrong with the connection, of course! With the returned hInternetSession handle used as a parameter to the other functions, you can start accessing Internet information. So Which one to prefer and am I interpreting correct that this call will make connection and return internet session as handle. RuchirDhar Dwivedi Software Engineer Windowmaker Software Pvt.Ltd. Baroda, India.

                  1 Reply Last reply
                  0
                  • R RuchirD

                    Hi I am writing an application which needs to know if the user is having internet connection enabled or not. I want this checking to be done automatically by the application, I donot want to pop up connect internet dialog. Can anyone tell me if there is any API/function to findout that the machine is having internet connection. Regards, Ruchirdhar Dwivedi RuchirDhar Dwivedi Software Engineer Windowmaker Software Pvt.Ltd. Baroda, India.

                    M Offline
                    M Offline
                    Michael Dunn
                    wrote on last edited by
                    #10

                    See the FAQ 8.7 How do I tell if the computer is connected to the Internet?[^] --Mike-- LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ | You Are Dumb Strange things are afoot at the U+004B U+20DD

                    1 Reply Last reply
                    0
                    • R RuchirD

                      Hi I am writing an application which needs to know if the user is having internet connection enabled or not. I want this checking to be done automatically by the application, I donot want to pop up connect internet dialog. Can anyone tell me if there is any API/function to findout that the machine is having internet connection. Regards, Ruchirdhar Dwivedi RuchirDhar Dwivedi Software Engineer Windowmaker Software Pvt.Ltd. Baroda, India.

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #11

                      See here.


                      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups