Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Check internet connection in Linux
Forum Updated to NodeBB v4.3 + New Features

Check internet connection in Linux

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 829 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.
  • H Offline
    H Offline
    hbatalha
    wrote on last edited by
    #1

    I need a reliable way to check for internet availability in linux using standard C++ or Qt C++. I thought that would be a trivial task but I searched everywhere and all the solutions I found was some kind of hack using ping or curl.

    Ping was the most common solution I found but I don't want to use it because it requires to ping a host and that's not reliable since the program could be running in a country that blocks that host, like google.com in China.

    I have, however, found a way to do check internet connection in Windows here with this code:

    bool ReachabilityCheck::internetAvailable()
    {
        bool result = true;
    
        DWORD lpresult;
        BOOL winresult = InternetGetConnectedState(&lpresult,0);
        result = winresult == 1 ? true : false;
    
        return result;
    }
    

    And now I am looking for a way to to achieve that in a linux environment.

    Any help or insight is appreciated! Thanks!

    JonBJ 1 Reply Last reply
    0
    • H hbatalha

      I need a reliable way to check for internet availability in linux using standard C++ or Qt C++. I thought that would be a trivial task but I searched everywhere and all the solutions I found was some kind of hack using ping or curl.

      Ping was the most common solution I found but I don't want to use it because it requires to ping a host and that's not reliable since the program could be running in a country that blocks that host, like google.com in China.

      I have, however, found a way to do check internet connection in Windows here with this code:

      bool ReachabilityCheck::internetAvailable()
      {
          bool result = true;
      
          DWORD lpresult;
          BOOL winresult = InternetGetConnectedState(&lpresult,0);
          result = winresult == 1 ? true : false;
      
          return result;
      }
      

      And now I am looking for a way to to achieve that in a linux environment.

      Any help or insight is appreciated! Thanks!

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @hbatalha
      This has been asked before, and the conclusion was: nothing better than trying to connect to google.com, or whatever equivalent for you.

      1 Reply Last reply
      0
      • gde23G Offline
        gde23G Offline
        gde23
        wrote on last edited by
        #3

        This is more a philosophical than a programming question.
        From the technical point of view the internet is just a network.
        So how do you define "the internet".
        If you say there has to be some webpage available then per that definition there is no internet in countries where it its blocked but some local other net.

        If you need the information to know if you can contact a server then just directly try to contact it or what is the purpose of knowing if there is some internet around?

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved