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. Generating list of all possible IP in Subnet
Forum Updated to NodeBB v4.3 + New Features

Generating list of all possible IP in Subnet

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 781 Views 2 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.
  • F Offline
    F Offline
    Foufy
    wrote on last edited by
    #1

    Hi,
    I can't found a simple solution to obtain a list of all available ip addresses in a given subnet.
    For exemple if I give the ip (192.168.1.1) with the subnet mask (255.255.255.0) I need a returned list of all addresses from 192.168.1.0 to 192.168.1.255.

    In other word I want to write a method like this :

    QList<QHostAddress> getAllAddresses(QHostAddress ip, QHostAddress subnetMask);
    

    Any suggestion?
    Regads

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Foufy said in Generating list of all possible IP in Subnet:

      Any suggestion?

      Iterate from 0 to 256 and add the generated IPs to your QList

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • F Offline
        F Offline
        Foufy
        wrote on last edited by
        #3

        That's an idea but I need a generic function working for any possible ip, subnet pair

        Christian EhrlicherC 1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi
          You can have a look here for inspiration
          http://www.cplusplus.com/articles/4S2z3TCk/

          1 Reply Last reply
          0
          • F Foufy

            That's an idea but I need a generic function working for any possible ip, subnet pair

            Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Foufy said in Generating list of all possible IP in Subnet:

            but I need a generic function working for any possible ip, subnet pair

            So where's the problem?

            btw: It's even easier - IPv4 is a simple 32bit integer counting up. So 192.168.1.1 is 0xc0.0xa8.0x01.0x01 = 0xc0a80101 = 3232235777. So simply count up and you get your ips.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            F 1 Reply Last reply
            1
            • Christian EhrlicherC Christian Ehrlicher

              @Foufy said in Generating list of all possible IP in Subnet:

              but I need a generic function working for any possible ip, subnet pair

              So where's the problem?

              btw: It's even easier - IPv4 is a simple 32bit integer counting up. So 192.168.1.1 is 0xc0.0xa8.0x01.0x01 = 0xc0a80101 = 3232235777. So simply count up and you get your ips.

              F Offline
              F Offline
              Foufy
              wrote on last edited by
              #6
              This post is deleted!
              1 Reply Last reply
              0
              • F Offline
                F Offline
                Foufy
                wrote on last edited by
                #7

                Is the IP list of a subnet always results in a continuous IP range? I that way counting is a simple solution indeed.

                1 Reply Last reply
                0
                • Christian EhrlicherC Online
                  Christian EhrlicherC Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Foufy said in Generating list of all possible IP in Subnet:

                  Is the IP list of a subnet always results in a continuous IP range?

                  I already told you in my first post...

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  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